I have a python application primarily dependent on matplotlib, tkinter, numpy and scipy I have been distributing for multiple operating systems. I build these on top of the python.org version of python 2.6. For mac, I have had good success in the past with py2app and pyinstaller to build standalone versions of my application. Recently, however, I have included functions that require patsy, pandas and igraph and have had to move to the mac distributed version of python 2.6 in order to get igraph to work. All works fine in building a py2app version of my software on the Mac for my OS (10.6) but when I run on 10.8 I encountered the following error:
Traceback (most recent call last):
File "UI.pyc", line 603 createHeatMap
File "clustering.pyc", line 31, in <module>
File "mpl_toolkits/__init__.pyc", line 2, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 698, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 701, in Environment
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 96, in get_supported_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 222, in get_build_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 98, in get_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 537, in get_config_vars
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 405, in _init_posix
DistutilsPlatformError: invalid Python installation: unable to open /user/include/python2.6/pyconfig.h (No such file or directory)
This is fixed by saving the file pyconfig.h to the designated location on the destination machine (not present in 10.8 but present in 10.6), which allows my application to work fine. In my py2app pacakge directory, under "Contents/Resources" there is a sym-link to the directory "include" which points to: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h. If I include the pyconfig.h file as an addition resource in my py2app setup file, it also includes it in the package, but it still is not recognized.
Can anyone suggest a good work around for this that doesn't require me to use the python.org version of python (I've had horrible luck getting igraph to work with this).
Thanks...
This is a known issue in py2app, see https://bitbucket.org/ronaldoussoren/py2app/issue/36/py2app-fails-to-build-a-working-executable. The pyconfig.h file is only present on machines where the developer tools are installed, which is why I haven't noticed the problem myself.
The easiest workaround is probably to replace the pyconfig.h symlink by a copy of the file after creating the app bundle.
Related
I made a simple, one-file script that I would like to share with the end-user. I found that Pyinstaller does the job so I refactor my project structure regarding.
I have a project dir. Inside that, I have the package that has an empty __init__.py and a __main__.py with the actual script with a few include to libraries like opencv-python, numpy, etc. Outside of the project, I have a setup.py and an entry-point script that imports the main function from the __main__.py and calls it.
Then I have created the executable against this entry-point with PyInstaller in --onefile mode. When I use the created executable on my machine it does the job perfectly but when I send it to the end-user it ends up with an error (see below). I am not quite sure whats this error means but I saw paths in that to my dev environment which should be not there on other machines. It looks like it missing the dependencies but I thought that PyInstaller bundles these dependencies into the executable.
What am I missing here? I have read many regarding questions here in StackOverflow but I couldn't find a solution.
I developed this script using PyCharm on the latest macOS within a venv created by PyCharm. The venv folder is in the project dir - I don't know that could be a problem.
Traceback (most recent call last):
File "PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 11, in <module>
File "/Users/hordon/Documents/DEV/projects/scan_detect/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
File "setuptools-40.8.0-py3.7.egg/pkg_resources/__init__.py", line 33, in <module>
File "/Users/hordon/Documents/DEV/projects/scan_detect/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
File "platform.py", line 116, in <module>
File "/Users/hordon/Documents/DEV/projects/scan_detect/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
File "subprocess.py", line 153, in <module>
ImportError: dlopen(/var/folders/wk/cwx1b16j50z5_yt1ynq82hr00000gn/T/_MEI7eUUkV/select.cpython-37m-darwin.so, 2): Symbol not found: ____chkstk_darwin
Referenced from: /var/folders/wk/cwx1b16j50z5_yt1ynq82hr00000gn/T/_MEI7eUUkV/select.cpython-37m-darwin.so (which was built for Mac OS X 10.15)
Expected in: /usr/lib/libSystem.B.dylib
in /var/folders/wk/cwx1b16j50z5_yt1ynq82hr00000gn/T/_MEI7eUUkV/select.cpython-37m-darwin.so
[15314] Failed to execute script pyi_rth_pkgres
i have the same problem ,and sadly it's a problem of mac os. So, if you want to support different version of mac os, you need to build your app on the oldest version of mac os.
"In Mac OS X, components from one version of the OS are usually compatible with later versions, but they may not work with earlier versions.
The only way to be certain your app supports an older version of Mac OS X is to run PyInstaller in the oldest version of the OS you need to support."
https://pyinstaller.readthedocs.io/en/stable/usage.html#making-mac-os-x-apps-forward-compatible
When I try the "python" or "python3" command to run the interpreter, this is the error am getting.
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.5/site.py", line 580, in <module>
main()
File "/usr/lib/python3.5/site.py", line 566, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python3.5/site.py", line 287, in addusersitepackages
user_site = getusersitepackages()
File "/usr/lib/python3.5/site.py", line 263, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/lib/python3.5/site.py", line 253, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/lib/python3.5/sysconfig.py", line 595, in get_config_var
return get_config_vars().get(name)
File "/usr/lib/python3.5/sysconfig.py", line 538, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/usr/lib/python3.5/sysconfig.py", line 410, in _init_posix
from _sysconfigdata import build_time_vars
File "/usr/lib/python3.5/_sysconfigdata.py", line 6, in <module>
from _sysconfigdata_m import *
ImportError: No module named '_sysconfigdata_m'
Output to which python
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ which python
/usr/bin/python
Output to python -V
[sidgupta234#sidgupta234-Lenovo-G580 Downloads]$ python -V
Python 3.5.2 :: Continuum Analytics, Inc.
Could you tell me the reason of this error and how can I remove it?
I found this link while looking for the solution, but it didnt make any difference.
I guess configuring_apache_django_anaconda is relevant, if you look at the troubleshooting section.
This means that apache is using Python 2 instead of Python 3 to run a program that is designed for Python 3 only, and fails because Python 2 does not have the _sysconfigdata_m module. The solution is to add the following file to your apache envvar file (/etc/apache2/envvar):
export PATH=/opt/anaconda3/bin:$PATH
So maybe check which version of python anaconda is running?
Also these two might be related:Linux - Weird Python Output
ubuntu anaconda suggested fix
I would suggest you print your PATH variable to see if you have several python3 entries in there, and try to specify explicity which one to run.
That is an strange situation you have gotten yourself into, and if Continuum had any part of it (where I'm an engineer) we'd like to understand what we did that led to it so we can avoid it in the future.
Where did you try installing Anaconda? Did you set any environment variables?
The "easiest-to-resolve" cause of this problem is that you have set some environment variables that are mixing system Python libraries and Anaconda Python libraries. You should look at the output of:
env | grep -i anaconda
and see if anything comes up that specifies a path to Anaconda. The only one that should appear is an entry in PATH. If there are any LD_LIBRARY_PATH, PYTHONPATH, PYTHONHOME or similar environment variables that point to Anaconda then that is going to be a problem.
The only other thing I can think of is that you specified /usr as the install path for Anaconda. If that is the case you are probably in for a world of pain: you have just replaced your system Python with Anaconda. You should investigate how to force-reinstall whichever Python package comes with your *nix distribution, but even that might be tricky: tools such as yum are written in Python and will need a working system Python interpreter to work. But RPM is binary (if you're on a RedHat or derivative distro), so maybe you can wget or curl the necessary system Python packages and force-install them to try and fix things.
Let us know if that is enough information for you to fix things or at least identify the source of the problem a little better.
This has been asked a couple of times but the answers do not make any sense at least to me. I have Ubuntu 12.04 and had to upgrade Python from default (2.7.3?) to 2.7.5 to get libraries I can use to compile modwsgi.
I obtained 2.7.5 sources, configured with --enable-shared, made and installed. A few obsolete sun audio etc libraries could not be built but otherwise the installation went through. Except that it doesn't work:
visti#ubuntu:~$ python
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
The suggested solution here ubuntu ImportError: cannot import name MAXREPEAT was to reconfigure "virtualenv", whatever it is. /usr/local/bin has an ancient script named virtualenv but it tries to run python as well and doesn't work.
Someone suggested the problem might be related to using old Python modules as MAXREPEAT appeared in 2.7.4. To counter this I removed everything related to Python with rm -rf (/usr/bin/python*, /usr/lib/python*, /usr/local/lib/python*, /usr/local/bin/python*, did make clean, make, make install to 2.7.5.
Still the same result. Now I don't have a working version of Python anymore. Is there any way to fix this or should I try reinstalling Ubuntu Python packages if they have 2.7.5 available?
Hannu
Just battled the same problem. Ended up deleting the entire /usr/local/lib/python2.7 install path just to get back to the previous working version.
Also be sure to remove /usr/local/lib/python2.7-config, then reinstall python. Worked for me anyway.
This usually happens when you mix and match libpython.so versions with python interpreter versions. If nuking your install paths didnt help, check these environment variables.
$PYTHONHOME $PYTHONINCLUDE $PYTHONLIB $PYTHONLIBSTATIC $PYTHONPATH
Make sure what they point to were all deleted as well. And then reinstall.
You can also try and install python to a home directory, by configuring the -prefix variable to point to a home dir.
make configure -prefix=$HOME/mypython`
Then make sure you set those above variables to the new home directory python resides in.
The way I fixed this was by searching my system for other instances of the sre_constants.py file. Then see if the location of those files is referenced in your user or system $PATH. If so, remove that location configuration from your $PATH. Rerun python to see if that fixed it.
In my case, it seemed that Python is referencing the wrong location which does not does not support MAXREPEAT.
I have created a simple program which uses pywin32. I want to deploy it as an executable, so I py2exe'd it. I also didn't want a huge amount of files, so I set bundle_files to 1 (meaning bundle everything together). However, when I attempt running it, I get:
Traceback (most recent call last):
File "pshelper.py", line 4, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32.pyc", line 8, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32ui.pyd
In my setup script, I tried doing packages=["win32ui"] and includes=["win32ui"] as options, but that didn't help. How can I get py2exe to include win32ui.pyd?
I don't have this problem if I don't ask it to bundle the files, so I can do that, for now, but I'd like to know how to get it to work properly.
Are you sure that the problem is that win32ui.pyd is not included? The stack trace isn't exactly the same as noted in the wiki, but check this out: http://www.py2exe.org/index.cgi/Py2exeAndWin32ui.
The work-around that has worked best so far is to simply re-implement the pywin32 functions using ctypes. That doesn't require another .pyd or .dll file so the issue is obviated.
Do care to try out PyInstaller? I've used it both on Windows 7 and Ubuntu 10.04 and it worked like magic, even when I compiled to .pyd on Windows.
I've been able to bundle all sorts of applications that I've developed with it.
I have the same problem trying to bundle psutil with py2exe. Here is what I found so far.
Traceback (most recent call last):
File "wx_gui.py", line 43, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\__init__.pyc", line 85, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "psutil\_psmswindows.pyc", line 15, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading _psutil_mswindows.pyd
I get this traceback when bundle_files = 3. zipfile may be specified or may be None, I still get the problem.
First, I thought this was a missing dll because of this page:
http://www.py2exe.org/index.cgi/ProblemsToBeFixed
I've copied all the dlls I found in Python27 into the same directory as the executable and added that directory path to os.environ['path']. That didn't worked.
Then I tried to import my package directly from site-packages.
I've replaced the whole sys.path of my compiled executable with my normal sys.path
sys.path = [r'C:\Python27\Lib\idlelib', ...]
I think the .pyd module got imported but Visual c++ threw me this really ugly error message:
Runtime Error!
Program: {path}.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I suggest you try to replace the whole sys.path to see if it is working. If it is, you could always make your single executable write the necessary module into a temp directory and add it to your path. If not, I feel like this problem is going to be hard to solve.
I use one c++ dll in my python code.
When I run my python app on my computer, it works fine but when I copy all to another computer this happen:
Traceback (most recent call last):
File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\SoundLog.py", line 9, in <module>
from Auxiliar import *
File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar\DataCollection.py", line 4, in <module>
import SoundLogDLL
File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar\SoundLogDLL.py", line 4, in <module>
dll = cdll.LoadLibrary(os.environ['PUBLIC'] + "\\SoundLog\\DLLs\\ForPython\\SoundLogC++WrapperDLL.dll")
File "C:\Python26\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "C:\Python26\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 14001] The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail
How can I fix this problem so that my python app work in every computer?
Note:
I only need them to work on windows 7 like mine. And I tested on another win7 computer (both 32bits).
You're using a DLL which depends on a Microsoft Visual C++ runtime which isn't installed on the target computer. You have a few options:
Install or copy the Visual C++ runtime libraries to the target computer. Installation is done by adding merge modules to your installer (if you have one) or by running the redistributable installer (vcredist.exe). The various methods are documented here for VS2005 (other versions will be similar).
If you built the DLL, you can change the project settings to statically link the runtime libraries. See this answer to see how this is done.