Pyinstaller failed to build wxpython app with error wx._xml missing - python

I tried to build my wxpython app with Pyinstaller, it built ok but when run, an exception occurred with message:
File "wx_gui.py", line 11, in <module>
import wx.xrc
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\wx\xrc.py", line 10, in <module>
File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 573, in load_module
module = loader.load_module(fullname)
ImportError: No module named 'wx._xml'
Failed to execute script ir2_main
I checked in the site-packages folder and there was no wx._xml.pyd like there was wx._xrc.pyd. Could this be the reason and how can I fix it ?

As you seem to use Python 3.4 therefore you can only use wxPython Phoenix.
Looking into the last snapshot build wheel from end of October 2016 there is actually a _xml.pyd there, so maybe you have a bonkers wxPython installation?

Related

How to solve ModuleNotFoundError: No module named 'openpyxl.cell._writer'?

I am trying to build an exe file for the GUI that I created using python POyqt5. After completing the process, I try to launch the UI and I get the following error:
Traceback (most recent call last):
File "main_3.py", line 14, in <module>
import openpyxl
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\___init__.py", line 6, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\workbook\____init__.py", line 4, in <module>
File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
File "openpyxl\workbook\workbook.py", line 9, in <module>
File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
File "openpyxl\worksheet\_write_only.py", line 13, in <module>
File "openpyxl\worksheet\_writer.py", line 23, in init openpyxl.worksheet._writer
ModuleNotFoundError: No module named 'openpyxl.cell._writer'
[13336] Failed to execute script 'main_3' due to unhandled exception!
I have openpyxl installed and I have also got it imported in my python script. Still, this error remains. Any leads on solving this will be appreciated.
Thanks!
Assuming you are creating the .exe with pyinstaller, try:
pyinstaller YOUR_FILE.py --hidden-import openpyxl.cell._writer
It lets pyinstaller know that openpyxl.cell._writer must be imported. It seems like this module import is done in a "hidden" way in your Python script. Therefore, it is not visible for pyinstaller and must be mentioned explicitly.
downgrade openpyxl to version 3.0.9 will also help. it works for me.
pip unistall openpyxl
pip install openpyxl=3.0.9

Building an executable with PyInstaller on Windows

I want to create a Windows executable using PyInstaller.
My project has the following dependencies:
deepspeech
PyAudio (which in turn depends on the PortAudio C library)
tkinter
I tried building the executable by running the command below:
pyinstaller entrypoint.py --name speech-to-text-gui --onedir --hidden-import numpy.random.common --hidden-import numpy.random.bounded_integers --hidden-import numpy.random.entropy
I initially tried building without any --hidden-import arguments, but then I would get errors like
ModuleNotFoundError: No module named 'numpy.random.common'
After the build, when I run the executable, it crashes with the following traceback:
Traceback (most recent call last):
File "entrypoint.py", line 1, in
from speech_to_text_gui.__main__ import main
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "speech_to_text_gui\__main__.py", line 5, in
from speech_to_text_gui import speech_to_text_gui
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "speech_to_text_gui\speech_to_text_gui.py", line 16, in
from deepspeech import Model
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "deepspeech\__init__.py", line 23, in
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "deepspeech\impl.py", line 13, in
ImportError: DLL load failed: The specified module could not be found.
[12236] Failed to execute script 'entrypoint' due to unhandled exception!
The program runs fine when I run it directly with python entrypoint.py.
I looked through the PyInstaller "If Things Go Wrong" page but nothing jumped out at me as wrong with how I am building.
I also tried building on Linux, and the executable built and ran just fine without any runtime errors on Linux.
From the traceback, my guess is loading a DLL for deepspeech failed, since that is the last call in the traceback. But take that with a grain of salt.
I am looking for any suggestions anyone might have to troubleshoot this build.

how to fix environment error in open-ai gym?

code:
import gym
env = gym.make('Breakout-v0')
I get an error:
Traceback (most recent call last):
File "C:/Users/danie/Downloads/Programming/Python/Programming/Pycharm/app.py", line 40, in
gym.make("Breakout-v0")
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 156, in make
return registry.make(id, **kwargs)
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 101, in make
env = spec.make(**kwargs)
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 72, in make
cls = load(self.entry_point)
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 17, in load
mod = importlib.import_module(mod_name)
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\importlib_init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in find_and_load_unlocked
File "", line 677, in load_unlocked
File "", line 728, in exec_module
File "", line 219, in call_with_frames_removed
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\atari_init.py", line 1, in
from gym.envs.atari.atari_env import AtariEnv
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\atari\atari_env.py", line 9, in
import atari_py
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\atari_py_init.py", line 1, in
from .ale_python_interface import *
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\site-packages\atari_py\ale_python_interface.py", line 18, in
'ale_interface/build/ale_c.dll'))
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\ctypes_init.py", line 434, in LoadLibrary
return self.dlltype(name)
File "C:\Users\danie\AppData\Local\Programs\Python\Python37\lib\ctypes_init.py", line 356, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
I was finally able to get around this problem with help from the following website: https://towardsdatascience.com/how-to-install-openai-gym-in-a-windows-environment-338969e24d30.
There were basically 3 things I had to do: 1) install Microsoft Visual C++ Build Tools, 2) install this specific verion of Atari https://github.com/Kojoley/atari-py.git, 3) Install Xming. Good luck to all Windows users :) This took me around 3 days to figure out.
I have tried to make it work with python 3.8 and 3.9 on Windows 10. Installing Python 3.7 and using it as the Python Interpreter on PyCharm resolved the issue. I have searched for the missing file while having 3.8 + version of Python and it did not exist at all. Atari-py is supported only for Python 3.7 (https://github.com/openai/atari-py) so having a higher version of that would not work. It is a bad idea to download files from unlicensed places so I advise you to install the supported version of Python (3.5, 3.6, and 3.7). Even though gym can work on 3.9 the atari version will not. I did not need anything else installed (although I may have Microsoft Visual C++ Build Tools, but I deff did not need Xming), just import gym 0.18.0, pyglet 1.5.0, atari -py 0.2.6
Welcome to SO. If you trace the exception trace you see that a shared object loading function is called in ctypes' init.py file aliased as dlopen. On Windows, this correponds to WINAPI's LoadLibrary method. LoadLibrary is trying to load ale_c.dll. ALE is 'arcade learning environment'.
Search your computer for ale_c.dll or libale_c.dll
If you have ale_c.dll (most likely you are on Windows), refer to this answer to see how DLL's loaded with ctypes are basically LoadLibrary calls as I mentioned. It mentions all the stuff about DLL loading order etc. but, if you need a quick way around this, copy your dll under system32 folder.
I had similar issue with Atari-Pacman. It is resolved by downloading atari_py-1.2.1-cp37-cp37m-win_amd64 which is for 64-bit Python 3.7, and installing it by using pip.

ImportError: No module named _tkinter_finder

I am packaging my application using pyinstaller. It created the binary file, but it is not working. When I load the application on terminal I see this error
[9854] LOADER: Running BC_GUI_Client.py
Traceback (most recent call last):
File "FALCON_BC_CLIENT/BC_GUI_Client.py", line 145, in <module>
File "PIL/ImageTk.py", line 127, in __init__
File "PIL/ImageTk.py", line 192, in paste
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyimod03_importers.py", line 687, in load_module
module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: No module named _tkinter_finder
[9854] Failed to execute script BC_GUI_Client
I am using python 2.7 and installed pyinstaller 3.3
Anything wrong here?
I was able to resolve a simiar issue by running pyinstaller with the following option added in the command:
--hidden-import='PIL._tkinter_finder'
Your command should look like this:
pyinstaller module.py --hidden-import='PIL._tkinter_finder'

Pyinstaller app(console) won't work

I've trouble making an CONSOLE app work after packaging.
App flashes once and closes.
in terminal i've put: pyinstaller --onefile --windowed --icon=name.icns Script.py
So far i've tried running the app through terminal to try and get error ( you know like in windows but it failed lol ).
Is there a way to see the reason why it closed?
EDIT:
When i run Executable within app i get this error:
File "Script.py", line 14, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages/requests/__init__.py", line 43, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages/urllib3/__init__.py", line 8, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages/urllib3/connectionpool.py", line 28, in <module>
File "site-packages/urllib3/packages/six.py", line 92, in __get__
File "site-packages/urllib3/packages/six.py", line 115, in _resolve
File "site-packages/urllib3/packages/six.py", line 82, in _import_module
ImportError: No module named 'queue'
I have nothing about "queue" in code and .py works great and gives no import error.
Thank you.
Seems like there's an error importing one of your modules, perhaps its dependencies aren't being detected correctly.
You can try to explicitly add a module via the command line by including --hidden-import=queue, you might have to do this for more modules that haven't been detected. More discussion in this question.

Categories