Building an executable with PyInstaller on Windows - python

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.

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

ImportError: No module named _shim

I am using PyInstaller to generate an executable from a python script. This is what I did:
sudo python2 -m PyInstaller ptemplatized.spec
It builds successfully the .exe but when I execute it I get the following error:
[19878] LOADER: Running pyi_rth_mpldata.py
[19878] LOADER: Running pyi_rth_multiprocessing.py
[19878] LOADER: Running pyi_rth__tkinter.py
[19878] LOADER: Running pyi_rth_pkgres.py
[19878] LOADER: Running physiocap_templatized.py
Traceback (most recent call last):
File "/home/abderrahmen/Bureau/PC/pour/physiocap_templatized.py", line 38, in <module>
import geopandas
File "/tmp/pip-build-2qvLhV/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 395, in load_module
File "/usr/local/lib/python2.7/dist-packages/geopandas/__init__.py", line 5, in <module>
from geopandas.io.file import read_file
File "/tmp/pip-build-2qvLhV/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 395, in load_module
File "/usr/local/lib/python2.7/dist-packages/geopandas/io/file.py", line 4, in <module>
import fiona
File "/tmp/pip-build-2qvLhV/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 395, in load_module
File "/home/hadoop/.local/lib/python2.7/site-packages/fiona/__init__.py", line 83, in <module>
from fiona.collection import BytesCollection, Collection
File "/tmp/pip-build-2qvLhV/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 395, in load_module
File "/home/hadoop/.local/lib/python2.7/site-packages/fiona/collection.py", line 9, in <module>
from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
File "/tmp/pip-build-2qvLhV/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 684, in load_module
File "fiona/ogrext.pyx", line 1, in init fiona.ogrext
ImportError: No module named _shim
[19878] Failed to execute script ptemplatized
I tried looking for the module but it seems to not exist. Thank you.
EDIT:
So I got this answer on another website:
Fiona has extension modules and some fairly complicated logic in its
setup script to manage them with respect to different versions of the
GDAL library. This is why python setup.py build (as reported in
another issue) won't work, you have to do python setup.py build_ext
build. I think you'll need to find a way for pyinstaller to run the
build_ext command defined in fiona's setup.py and then you'll be all
set.
Can anyone tell me how can that be done in my case?
EDIT2:
I countred this error by installing an ancient gdal version using a tuto. Now my Pyinstaller creates the .exe without errors bur when I execute it on another Machine I get the same error. Isn't the goal from using PyInstaller is to execute an .exe file without having to install all modules? Why am I having an import error if PyInstaller worked well and created a proper .exe? Thanks

Pyinstaller throws "Import Error:requests> 2.18.0 is required by the google.resumable media.requests subpackage."

I used pyinstaller to convert my .py file to .exe, but as i try to execute the exe it throws the following error:
Import Error:requests> 2.18.0 is required by the google.resumable media.requests subpackage.
My pip version is : pip 19.1.1
here's the code i used :
pyinstaller -F AdminPanel.py
i tried installing it using pip, but it says that its already installed.
Thanks in advance
Complete Error is:
Resources.Distribution Plot Found: The requests-2.18.0 distribution was not found and is required by the
The above exception as the direct cause of the following exception:
Network
Traceback (most recent call last):
File AdninPanelUI.py, line 11, in module>
File "d: Nother stuffiapplications\python\installation\lib\site-packages\PyInstaller\loader\pyimod83_importer
627, in exec_module
exec(bytecode, module. dict)
File "site-packages\google cloud storage__init__.py", line 39, In <module>
File "d: other stufflapplications\python\installation\llb\site-packages\PyInstaller\loader\pyimode3_importer
627, in exec_module
exec(bytecode, module. dict)
File site-packages\google cloud storage\blob.py", line 44, in <module
File "d: other stuff applications\python\installation\lib site-packages\PyInstaller loader\pyimode3_importer
627, in exec_module
exec(bytecode, module. dict)
File "site-packages\google\resumable_media\requests_init_.py", 1ine 673, in <module>
File string", 1ine 3, in raise from
ImportError:requests
2.18.e is required by the google.resumable_media.requests
subpackage.
It can be installed via
pip Install google-resumable-media[requests).
17008) Failed to execute script Admin Panel
This is how i fixed the error :
Made a hook(python file) named it
hook-google.resumable_media.requests
and the content of it is as follow :
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('requests')
Then after just past this file to the hooks folder inside pyinstaller where all the other hooks are.
Hope it fixed the error for you.

Converting py file to exe, Cannot find existing PyQt5 plugin directories

I'm quite new to phyton and I've just finished my first application.
Now, I'm trying to compile my .py file to an .exe buy that doestn seem to work.
I've looked everywhere for a solutio to my problem, but I just cant seem to find one.
When I run this command: pyinstaller gui.py
this error shows up:
4815 INFO: Loading module hooks...
4815 INFO: Loading module hook "hook-encodings.py"...
4913 INFO: Loading module hook "hook-pydoc.py"...
4913 INFO: Loading module hook "hook-PyQt5.py"...
5019 WARNING: Hidden import "PyQt5.sip" not found!
5019 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
5096 WARNING: Unable to find Qt5 translations C:/qt5b/qt_1524647842210/_h_env/Library/translations\qtbase_*.qm. These translations were not packaged.
5096 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
Traceback (most recent call last):
File "c:\users\ivo\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\ivo\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Ivo\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 17, in <module>
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
self.__postinit__()
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
module_hook.post_graph()
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
self._load_hook_module()
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 823, in load_module
File "<frozen importlib._bootstrap_external>", line 682, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in <module>
hiddenimports, binaries, datas = add_qt5_dependencies(__file__)
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 514, in add_qt5_dependencies
more_binaries = qt_plugins_binaries(plugin, namespace=namespace)
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 132, in qt_plugins_binaries
pdir = qt_plugins_dir(namespace=namespace)
File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 117, in qt_plugins_dir
""".format(namespace, ", ".join(paths)))
Exception:
Cannot find existing PyQt5 plugin directories
Paths checked: C:/qt5b/qt_1524647842210/_h_env/Library/plugins
My path variable:
C:\Users\Ivo\Anaconda3;C:\Users\Ivo\Anaconda3\Library\mingw-w64\bin;C:\Users\Ivo\Anaconda3\Library\usr\bin;C:\Users\Ivo\Anaconda3\Library\bin;C:\Users\Ivo\Anaconda3\Scripts;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\;C:\Users\Ivo\AppData\Local\Microsoft\WindowsApps;C:\Users\Ivo\AppData\Roaming\Composer\vendor\bin;C:\Users\Ivo\AppData\Local\atom\bin;C:\scrcpy-windows-v1.0\adb.exe;D:\xampp2\php;C:\Users\Ivo\AppData\Roaming\npm;
Ive been trying to fix this for a whole day now, if anyone could help me/ point me in the right direction that would be greatly appericiated.
edit:
Also, since i've reinstalled some things to try and fix the problem. the file wont start and gives this error:
Traceback (most recent call last):
File "C:\Users\Ivo\Documents\temp\project\gui.py", line 9, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.
Conda 4.5.11,
Python 3.6.4,
PyInstaller 3.4
The plugin path is determined incorrectly in hooks/qt.py. Qt requires that QCoreApplication is instantiated first, before any other calls.
My qt.py hook is in ~\anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py.
I edited it like so:
json_str = exec_statement("""
import sys
# exec_statement only captures stdout. If there are
# errors, capture them to stdout so they can be displayed to the
# user. Do this early, in case PyQt5 imports produce stderr
# output.
sys.stderr = sys.stdout
import json
from %s.QtCore import QLibraryInfo, QCoreApplication
# QLibraryInfo isn't always valid until a QCoreApplication is
# instantiated.
app = QCoreApplication([])
paths = [x for x in dir(QLibraryInfo) if x.endswith('Path')]
location = {x: QLibraryInfo.location(getattr(QLibraryInfo, x))
for x in paths}
try:
version = QLibraryInfo.version().segments()
except AttributeError:
version = None
print(str(json.dumps({
'isDebugBuild': QLibraryInfo.isDebugBuild(),
'version': version,
'location': location,
})))
""" % self.namespace)
see 1.
Try the fix in Exception: Cannot find PyQt5 plugin directories when using Pyinstaller despite PyQt5 not even being used. In short:
pip intall PyQt5
Note that, strangely enough, conda install PyQt5 may not fix the problem.
I encountered the same problem and saw another suggestion: make the missing directory (C:/qt5b/qt_1524647842210/_h_env/Library/plugins in your case) and copy the two files pyqt5.dll and pyqt5qmlplugin.dll (presumably somewhere in c:\Users[name]\AppData\Local\conda\conda\envs) to the directory.
I did not try it since I fixed the problem with pip install PyQt5. You may want to give it a try.
I am using Python 3.6.3 with ANACONDA3 and Spyder as IDE. Pyinstaller 3.4.
Trying to generate an exe file with Pyinstaller, I had two kinds of errors:
"AttributeError: 'str' object has no attribute 'items' ". This was resolved by
updating each module imported in the Python script, with :
pip install --upgrade <module_name>
"Cannot find existing PyQt5 plugin directories" :this was the next error. As
mentioned by cong yu in his previous post, I fixed this problem by running
pip install PyQt5
Do not forget to upgrade setuptools to the latest version as well
The process delivered an exe file which I have not yet tested.
But at least, I got Pyinstaller reaching the end without failing in error.
Hope this could be helpful
And, by the way, Happy New Year :)
Edit:
I have tested the standalone .exe produced by py2exe
The program is running and get to the end without errors.
But the problem is that xlsx is no more running, because no Excel
files are created. These files are based on pandas dataframes.
My hint is that pandas module, which is the main core of the program,
seems to be altered. I noticed that the dataframes used were truncated,
through the control lines edited in the Ipython console in Spyder.
I think that my best alternative is to reinstall Anaconda3.
So be careful, upgrading the modules used in the program you want as
standalone with py2exe. It seems that upgrading pandas module was a
mistake.
I am sorry, if I gave a bad advice in my main post, but upgrading was the
best way to run py2exe. Be careful with the upgrade of pandas.
Try uninstalling Anaconda. There have been issues in the past. If not you can try py2exe that is fairly decent too.
I installed the latest version of PyInstaller, then this exception of "Cannot find existing PyQt5 plugin directories" is addressed.
You can install the latest version of PyInstaller through the following command:
pip install https://github.com/pyinstaller/pyinstaller/tarball/develop
P.S: Some information about my setup:
$conda info
conda version : 4.6.14
conda-build version : 3.17.8
python version : 3.7.3.final.0
platform : win-64
user-agent : conda/4.6.14 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763
$ pip show pyinstaller
Name: PyInstaller
Version: 3.5.dev0+d74052489
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.

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

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?

Categories