Python executable importerror - python

I have a gui that I created with wx and a bunch of other libraries like matlabplot, win32api etc...
I have compiled the python code into an executable using py2exe.
The executable gets created but when I try to run it, it produces an error.
Traceback (most recent call last):
File "gui.py", line 30, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "guiupdater.pyc", line 22, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "paramiko\__init__.pyc", line 30, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "paramiko\transport.pyc", line 32, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "cryptography\hazmat\backends\__init__.pyc", line 7, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "pkg_resources\__init__.pyc", line 70, in <module>
File "pkg_resources\extern\__init__.pyc", line 61, in load_module
ImportError: The 'appdirs' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
I had previously compiled the executable and had it running in a different environment. I'm on a new environment now, but I have all the same dependencies installed etc...
I did some quick research and lots of people say reverting their setuptools to 19.2 version fixed it for them but I am relunctent to do that because my setuptools is at version 28.2. I feel like it would do more harm than good...
Does anyone know how to fix this error?

I had the same problem and as I did not want to go far back with versions I had to do some research...
Problem is that while processing pkg_resources.extern all necessary modules from (private?) default package pkg_resources._vendor are not found (delayed load).
Compare contents of pkg_resources._vendor at source (site-packages) and inside library.zip that is generated with executable. Whatever is missing in zip can be included by options for py2exe.
options={"py2exe": {"includes": ["pkg_resources._vendor.appdirs",...], ...

It's an issue introduced with newer versions of setuptools. Either:
add 'pkg_resources' to setuptools.setup packages option
or
Downgrade to version 19.2
pip install setuptools==19.2

Related

pip install with ensurepip on PyPy3.5 v5.10 in Windows 7 x64

Why I can't install pip with pypy3 -m ensurepip? I have unpacked PyPy from official package, and followed instructions at official docs but resulting in an error. Interpreter log is below.
Traceback (most recent call last):
File "D:\pypy3-v5.10.0-win32\lib-python\3\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "D:\pypy3-v5.10.0-win32\lib-python\3\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\pypy3-v5.10.0-win32\lib-python\3\ensurepip\__main__.py", line 4, in <module>
ensurepip._main()
File "D:\pypy3-v5.10.0-win32\lib-python\3\ensurepip\__init__.py", line 209, in _main
default_pip=args.default_pip,
File "D:\pypy3-v5.10.0-win32\lib-python\3\ensurepip\__init__.py", line 116, in bootstrap
_run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "D:\pypy3-v5.10.0-win32\lib-python\3\ensurepip\__init__.py", line 40, in _run_pip
import pip
File "C:\Users\user\AppData\Local\Temp\tmp5zq6hqua\pip-9.0.1-py2.py3-none-any.whl\pip\__init__.py", line 21, in <module>
File "C:\Users\user\AppData\Local\Temp\tmp5zq6hqua\pip-9.0.1-py2.py3-none-any.whl\pip\_vendor\requests\__init__.py", line 62, in <module>
File "C:\Users\user\AppData\Local\Temp\tmp5zq6hqua\pip-9.0.1-py2.py3-none-any.whl\pip\_vendor\requests\packages\__init__.py", line 27, in <module>
File "C:\Users\user\AppData\Local\Temp\tmp5zq6hqua\pip-9.0.1-py2.py3-none-any.whl\pip\_vendor\requests\packages\urllib3\__init__.py", line 8, in <module>
File "C:\Users\user\AppData\Local\Temp\tmp5zq6hqua\pip-9.0.1-py2.py3-none-any.whl\pip\_vendor\requests\packages\urllib3\connectionpool.py", line 101, in <module>
AttributeError: module 'errno' has no attribute 'EWOULDBLOCK'
The errno module on pypy3 on Windows (which is beta) is indeed incomplete. This has been fixed after the 5.10.0 release and will be included in the 5.10.1 release.
We build nightly zip files off the latest HEAD, available here. It would be great if you could try out the latest windows version and let us know on IRC at #pypy, or on the pypy-dev mailing list, or by filing an issue on our bitbucket issue tracker whether it works for you, so that we will not need to do a 5.10.2 bug release fix after the current one.

PyInstaller with NumPy under Linux

I am trying to convert my Python program into a stand-alone executable for Windows and Linux. It seemed that PyInstaller was a good solution for this task. It got converted very easily under Windows, however I cannot make it working with Linux (was probing it on two different Ubuntu machines). The original Python program could be reduced to the simple two-line code:
from numpy import log
print '%8.6f' % log(5)
Which is working fine when called like:
anton#op:~/bin$ python test_numpy.py
1.609438
After compilation in PyInstaller, it gives me that error:
anton#op:~/bin/dist/test_numpy$ ./test_numpy
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy", line 153, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.add_newdocs", line 13, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib", line 8, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.lib.type_check", line 11, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/anton/bin/build/test_numpy/out00-PYZ.pyz/numpy.core", line 6, in <module>
ImportError: cannot import name multiarray
So the problem is related to numpy library been not imported correctly.
I have tried adding hidden hooks as pyinstaller suggested, but nothing helps and I am always getting this error. Any ideas?
I was finally able to resolve this problem.
This is what I have found on hithub:
The executable that PyInstaller builds is not fully static, in that it still depends on the system libc. Under Linux, the ABI of GLIBC is backward compatible, but not forward compatible. So if you link against a newer GLIBC, you can't run the resulting executable on an older system. The supplied binary bootloader should work with older GLIBC. However, the libpython.so and other dynamic libraries still depends on the newer GLIBC. The solution is to compile the Python interpreter with its modules (and also probably bootloader) on the oldest system you have around, so that it gets linked with the oldest version of GLIBC.
So it appeared that the current stable PyInstaller version could be outdated. As it was not practical to downgrade all the packages, I upgraded the PyInstaller to the latest development release (3.0.dev2) and voilà! Everything is working now with all the dependencies correctly processed without any custom hooks.
Hope that could help someone.

Freezing (.exe) a traitsUI program, realistically feasible?

I'm trying to freeze with either cx_freeze or pyInstaller a TraitsUI program that makes use of Chaco, Traits, TraitsUI and to a lesser extent mayavi (could actually be taken out). I need this to run on mac, linux, ubuntu so am avoiding py2exe. I've intentionally uninstalled pyqt and pyside so that only the wx backend is available.
Using cx_freeze, I encountered and reported a bug, so pyInstaller seems to be getting me the furthest. It generated an .exe file, but when I run the file I get warnings and an error. To generate the .exe file I did:
pyinstaller --onefile --name=pameapp pamemain.py
pyinstaller pameapp.exe
Upon running, the warnings are:
Warning: Unable to import the wx backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named wx.init
Warning: Unable to import the qt4 backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named init
Warning: Unable to import the null backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named null.init
In addition, I get the following error:
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.api", line 35, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors", line 22, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.api", line 10, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 36, in <module>
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 48, in ToolkitEditorFactory
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 487, in __call__
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 1191, in Color
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit_traits", line 7, in ColorTrait
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit", line 137, in toolkit
traits.trait_errors.TraitError: Could not find any UI toolkit called 'null'
pyface probably has a lot of dynamic imports, so this must be a problem encountered by anyone who tries to freeze ETS. Is there a single fix to get this working?
Considering the older stuff floating around the web on success rates to freezing an ETS program, is it even worth further investment? To us, having people avoid configuring python for this application would be a huge plus.
Thanks.
Pyface.toolkit you are using is using dynamic import:
def import_toolkit(tk):
try:
# Try and import the toolkit's pyface backend init module.
be = 'pyface.ui.%s.' % tk
__import__(be + 'init')
except:
raise
return be
So pyinstaller is not able to detect this. Check with python -v b.py 2>&1 | grep imp what is the specific import and add hook file (hook-.py) with proper hiddenimports list.
However I've did some tests in local and I am not able to do working test schema with __import__. It's strange as I did some debugging and I found that hiddenimport is added but still not usable.

python django - no module psycopg2.extension even after installing compiled version psycopg2-2.4.5.win32-py2.7.‌exe

I am using python django on windows,and trying to deploy to heroku . When i tried to install psycopg2 using pip,
pip install psycopg2
i got error :
unable to find vcvarsall.bat
Then i found that i need to install visual studio 2008 (or) i can directly download and install compiled version , so downlaoded from this link :
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Filename i downloaded : psycopg2-2.4.5.win32-py2.7.‌exe
Even after installing this i am getting error : no module named psycopg2.extensions
So, what more should i do ?
D:\mycode\python\mysite>heroku run python manage.py syncdb
Running python manage.py syncdb attached to terminal... up, run.1
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/venv/lib/python2.7/site- packages/django/core/management/__i
nit__.py", line 443, in execute_from_command_line
utility.execute()
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/__i
nit__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "/app/.heroku/venv/lib/python2.7/site-packages/django/core/management/sql
.py", line 6, in <module>
from django.db import models
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line24, in load_backend
return import_module('.base', backend_name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py"
, line 35, in import_module
__import__(name)
File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 13, in <module>
from django.db.backends.postgresql_psycopg2.creation import DatabaseCreation
File "/app/.heroku/venv/lib/python2.7/site- packages/django/db/backends/postgre
sql_psycopg2/creation.py", line 1, in <module>
import psycopg2.extensions
ImportError: No module named psycopg2.extensions
D:\mycode\python\mysite>
While isntalling psycopg2 both by pip and easy_install, installdidnt work as i got this error : unable to find vcvarsall.bat with some msg : no previsouly included directores matching 'doc\src_build'
Thanks
Despite some claims on the Internet, psycopg2 DOES work in a VirtualEnv.
Download the correct version of win-psycopg2. Typically I use 32-bit Python 2.7 so I got psycopg2-2.4.5.win32-py2.7-pg9.1.3-release.exe.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
This worked for me, hope it works for you.
Take a look at http://slacy.com/blog/2010/09/python-unable-to-find-vcvarsall-bat/. It seems you need to install Microsoft Visual Studio Express to solve the vcvarsall.bat issue.
Pretty crazy...
Binaries from this link:
http://www.stickpeople.com/projects/python/win-psycopg/
In settings.py it should look like this in db settings
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
You CANNOT install this file into a VirtualEnv, but you can rename the .exe file to .zip and open with a utility like 7-Zip. You will get a folder called “psycopg2″ and a file called “psycopg2-2.4.5-py2.7.egg-info”. Copy these into:
[...]\Envs\MyVirtualEnv\Lib\site-packages
Yes, this work!

Mercurial CGI (hgweb.cgi) fails

I have Mercurial 1.8.1, Python 2.6.6 installed on Win 2k8 R2 running on a vm. I have tried installing from msi, source and using tortisehg. Command-line Hg works fine but I get the same error when running the hgweb.cgi:
Traceback (most recent call last):
File ".\hgweb.cgi", line 17, in
application = hgweb(config)
File "mercurial\hgweb\__init__.pyc", line 26, in hgweb
File "mercurial\hgweb\hgwebdir_mod.pyc", line 61, in __init__
File "mercurial\hgweb\hgwebdir_mod.pyc", line 70, in refresh
File "mercurial\ui.pyc", line 35, in __init__
File "mercurial\demandimport.pyc", line 75, in __getattribute__
File "mercurial\demandimport.pyc", line 47, in _load
File "mercurial\util.pyc", line 576, in
File "mercurial\demandimport.pyc", line 85, in _demandimport
File "mercurial\windows.pyc", line 21, in
File "mercurial\demandimport.pyc", line 75, in __getattribute__
File "mercurial\demandimport.pyc", line 47, in _load
File "mercurial\osutil.pyc", line 12, in
File "mercurial\osutil.pyc", line 10, in __load
ImportError: DLL load failed: The specified module could not be found.
The other answers I have found on SO and elsewhere pointed me to try installing from source, dropping the pure osutil into the install, or installing an older version. I have tried them all.
This is especially frustrating because I have other, similar non-vm machines running fine but have been unable to find the disconnect.
Ideas?
I had the same error using following system configuration
Python-2.6.6 installed as msi
mercurial-1.8.2-x86 installed as msi
IIS7
I solved this problem simply:
Python has been installed early
Uninstall Mercurial msi package
Download and install "Mercurial-1.8.2 (32-bit py2.6)" installer from mercurial website which is marked as "This is recommended for hgweb setups".
copyed content of C:\Python26\Lib\site-packages\mercurial\ to the directory used in IIS7 website setup.
Till now all is working. Hope this will help.
Whenever I have less than descriptive error messages that tell me something is going on at the system level but not what, I use Sysinternals' Procmon to tell me what's going with the registry and filesystem. It's verbose, and getting the filter to show just the process of interest takes some learning, but you can export the results to Excel and skim them for suspicious-looking results. Pay particular attention to failures, of course.
Give it a try and see what DLL is being searched for.

Categories

Resources