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
Related
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
I'm using py2app to package some Python scripts into an executable on Mac.
I get this error when running it:
...
File "/xxx.app/Contents/Resources/lib/python3.10/paddle/utils/cpp_extension/cpp_extension.py", line 20, in <module>
import setuptools
File "setuptools/__init__.pyc", line 18, in <module>
File "setuptools/dist.pyc", line 39, in <module>
File "setuptools/config.pyc", line 17, in <module>
File "setuptools/extern/__init__.pyc", line 52, in create_module
File "setuptools/extern/__init__.pyc", line 44, in load_module
ImportError: The 'packaging.specifiers' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
2022-12-12 23:35:59.913 xxx[92028:45291215] Launch error
2022-12-12 23:35:59.914 xxx[92028:45291215] Launch error
See the py2app website for debugging launch issues
Currently I have:
paddlepaddle==2.4.0
setuptools==59.8.0
packaging==21.3
How can I fix this?
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.
I’m making grpc server with python. My goal is to build an executable using cx_Freeze.
After I make greeter_server.exe using cx_Freeze, when I run greeter_server.exe, I meet this error.
Traceback (most recent call last):
File “greeter_server.py", line 19, in <module>
File “c:\users\User\anaconda3\envs\tensorflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module exec(bytecode, module.__dict__)
File “site-packages\grpc\__init__.py", line 22, in <module>
File “src\python\grpcio\grpc\_cython\cygrpc.pyx", line 18, in init grpc._cython.cygrpc
ModuleNotFoundError: No module named ‘pkg_resources'
My setup.py is like this.
import sys
from cx_Freeze import setup, Executable
build_exe_options = {}
setup(
name='py freeze test',
version='0.0.1',
description="greeter_server function test",
author="ray",
options={'build_exe':build_exe_options},
executables=[Executable("greeter_server.py")],
)
I tried a lot of tries.
pip install grp
pip install grpcio
pip install grpcio-tools
pip install --upgrade setuptools
pip install --upgrade distribute
But when I tried pip install —upgrade distribute I meet this error.
Collecting distribute
Using cached https://files.pythonhosted.org/packages/5f/ad/1fde06877a8d7d5c9b60eff7de2d452f639916ae1d48f0b8f97bf97e570a/distribute-0.7.3.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\dist.py", line 7, in <module>
from setuptools.command.install import install
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\command\__init__.py", line 8, in <module>
from setuptools.command import install_scripts
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\setuptools\command\install_scripts.py", line 3, in <module>
from pkg_resources import Distribution, PathMetadata, ensure_directory
File "C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\pkg_resources.py", line 1518, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\User\AppData\Local\Temp\pip-install-ao7m4k8f\distribute\
I’m using Anaconda3-5.2.0, Python 3.6.7. (Because I have to use tensorflow)
Any help will be appreciated.
pkg_resources needs to be added to the packages list of the build_exe options:
build_exe_options = {'packages': ['pkg_resources']}
Remark: other entries might be necessary in the packages list in order that the setup script works (these entries are found in the OP's own answer but are missing in the setup script of the question).
After editing setup.py file like bellow, it works.
build_exe_options = {
'packages':['grpc','pkg_resources', 'numpy', 'tensorflow'],
}
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'