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.
Related
I have a quesetion. I made a Python App and wanted to distribute this to friends.
I used PySimpleGui for the GUI and when I open the .py App with Python it works fine. But when I package it with PyInstaller and then open it I get this message:
/Users/USERNAME/Documents/Dev/application/dist/APPLICATION 1 ✘ 14:57:29
Traceback (most recent call last):
File "stamp.py", line 5, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/__init__.py", line 2, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/PySimpleGUI.py", line 111, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "tkinter/__init__.py", line 37, in <module>
ModuleNotFoundError: No module named '_tkinter'
[53336] Failed to execute script 'APPLICATION' due to unhandled exception!
Im using MacOS with Big Sur 11.5, Python 3.9.6 (with Pyenv) and PyInstaller 4.5.1.
I already tried troubleshooting with:
Reinstalling PySimpleGui
Reinstalling tkinter
use "hidden imports" for both
...
but nothing works...
Can I bundle tkinter with the application?
Im trying to convert a single file python script/project into an exe using pyinstaller
Even thought pyinstaller converts the script the .exe will run and throw this
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[16676] Failed to execute script main
I'm stumped , through my trial and erroring i figured that when i replace pynput with a module like random the convertion works fine , but i need it to work with pynput
please help , thanks in advance!
Authors made some changes which i feel broke the reference.
so instead of package it is referring file.
- backend = backend(__package__)
+ backend = backend(__name__)
pls try to downgrade your package and check that your app still works.
pip install pynput==1.6.8
then your command like following would work.
pyinstaller --onefile build_pkg_for.py
I want to transform a simple .py code into .exe using PyInstaller, the program works fine with python, but when I transform it into .exe using PyInstaller, it returns the error:
ModuleNotFoundError: No module named numpy.core._dtype.ctypes
I tried installing the ctypes module, but the same error happenened.
How can I fix this error?
.py code:
import numpy
input("Worked")
cmd output:
C:\Users\enzo\Desktop\Compilando\dist\iaf>iaf.exe
Traceback (most recent call last):
File "iaf.py", line 1, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\__init__.py", line 151, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\ctypeslib.py", line 369, in <module>
File "site-packages\numpy\ctypeslib.py", line 358, in _get_typecodes
File "site-packages\numpy\ctypeslib.py", line 358, in <dictcomp>
ModuleNotFoundError: No module named 'numpy.core._dtype_ctypes'
[2872] Failed to execute script iaf
after I added to the beginning of the code:
import numpy.core._dtype_ctypes
my code works
spied on KmolYuan
As an alternative solution, you can downgrade your numpy package via
python -m pip install numpy==1.15.0
as there seems to be a problem for pyinstaller using the current numpy release (1.16.0).
Yesterday I installed the mysql connector package, today I can't start python anymore. Anacona won't start nor directly Python 3.6. The Anaconda prompt delivered:
Microsoft Windows [Version 10.0.17134.48]
(c) 2018 Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\ric22>python.exe -m idlelib.idle
Error processing line 1 of C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site-packages\protobuf-3.5.2.post1-py3.6-nspkg.pth:
Failed to import the site module
Traceback (most recent call last):
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py", line 9, in <module>
from ... import exc, util
ImportError: attempted relative import with no known parent package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 544, in <module>
main()
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 531, in main
known_paths = addsitepackages(known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 328, in addsitepackages
addsitedir(sitedir, known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 178, in addpackage
import traceback
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 8, in <module>
import functools
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\functools.py", line 22, in <module>
from types import MappingProxyType
File "D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py", line 9, in <module>
from ... import exc, util
ImportError: attempted relative import with no known parent package
Does anyone have an idea how to make Python run again? Thanks in Advance
Ric
Thanks amphibient,
I had set this environment variable 'cause I couldn't make mysql package work on Spyder:
D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py
(Now I see .py is obviously no folder ;))
This messed everything up. I removed it and installed the package with
conda install mysql-connector-python typed into conda path.
Now everything works.
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