i write a program that detected and recognition visitors with face_recognition . i try to make exe file with pyinstaller .it's make .exe file but when i run the .exe it has an error.
E:\python source\python examples\Visitors\dist>main_window.exe
Traceback (most recent call last):
File "main_window.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "e:\python source\python-3.9.1\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
def find_spec(self, fullname, path=None, target=None):
File "face_recognition\__init__.py", line 7, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "e:\python source\python-3.9.1\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
def find_spec(self, fullname, path=None, target=None):
File "face_recognition\api.py", line 20, in <module>
RuntimeError: Unable to open C:\Users\SHAHRA~1\AppData\Local\Temp\_MEI144802\face_recognition_models\models\shape_predictor_68_face_landmarks.dat
[13080] Failed to execute script main_window
my source code on github :
"** https://github.com/shahram-arefhakimi/Visitors_with_PySide2 **"
I have come through this issue previously and there is a solution to it. When you type this in the terminal (cmd or PowerShell):
pyinstaller --onefile -w filename.py
if you remove the
-w
so it is just
pyinstaller --onefile filename.py
then you will be able to run the exe fine
This will work 99% but if not, then there is a possibility that you have an error in your code
Related
So I have been working on a battleship game project in pygame and wanted to start recording game results to help with building an AI. Unfortunately when I go through with this command for pyinstaller:
pyinstaller -D -w -n Battleship -F Gui.py
It goes through and creates the exe with no issue, when I go to launch the exe it throws this error seen in the picture below.
Following that path in the error it seems to be when I call my database script then when I try and import pymongo. If I exclude the database side of my script when I make the exe it runs just find and of course is just missing the database interaction portion.
I am running this through pycharm and it works just fine in this development setting but again when I go to create an exe through pyinstaller it results in the error.
Edit 1: So I have run this now without the -w in cmd window and recieved the following:
C:\Users\14402\SynologyDrive\BattleShip\dist>Battleship.exe
Traceback (most recent call last):
File "Gui.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "DataBase.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\__init__.py", line 102, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\collection.py", line 38, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\common.py", line 42, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\compression_support.py", line 18, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "snappy\__init__.py", line 20, in <module>
File "snappy\__init__.py", line 11, in _delvewheel_init_patch_0_0_9
File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\14402\\AppData\\Local\\Temp\\_MEI1811162\\python_snappy.libs'
[152752] Failed to execute script 'Gui' due to unhandled exception!
Along with this I have checked to see if python-snappy is installed and it is:
PS C:\Users\14402\SynologyDrive\BattleShip> pip install python-snappy
Requirement already satisfied: python-snappy in c:\users\14402\synologydrive\battleship\venv\lib\site-packages (0.6.1)
WARNING: Error parsing requirements for pytz: [Errno 2] No such file or directory: 'c:\\users\\14402\\synologydrive\\battleship\\venv\\lib\\site-packages\\pytz-2022.2.1.dist-info\\METADATA'
Finally I will be going through tomorrow and seeing if I can make a simplified version to see if I can better pinpoint, but from my testing this gets thrown when the exe is starting and hits the import for pymongo.
So after Alexander said they were able to open things and run it no problem. I created a new project and pulled over all the code and reimported the libraries and it ran just fine. I must have something hanging over in my previous project in my library that is causing the problem but it is resolved now! Thank you all for your questions and help, first time posting and it was a bit rough.
I am trying to make a executable of a python script, this script is for use with the google drive api, i have copy and paste the token.pickle file, and the client_secret.json file inside the folder where the .exe is but i have this traceback when i execute the script
Traceback (most recent call last):
File "Myscript.py", line 12, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "googleapiclient\discovery.py", line 68, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "googleapiclient\http.py", line 67, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "googleapiclient\model.py", line 36, in <module>
File "pkg_resources\__init__.py", line 465, in get_distribution
File "pkg_resources\__init__.py", line 341, in get_provider
File "pkg_resources\__init__.py", line 884, in require
File "pkg_resources\__init__.py", line 770, in resolve
pkg_resources.DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
[13660] Failed to execute script Myscript
it seems like some modules are not found in the executable , the comand i used to convert the .py file into .exe was
pyinstaller -c -F myscript.py
how can i ensure that the required modules are included in the exe file
You need to add google-api-python-client to the package
I am trying to package up a script with pyinstaller that uses the skyfield module/API, and it builds, but when I run it, it dies saying it can't find nutation.npz (a data file included in the nutationlib.py _arrays = load_bundled_npy('nutation.npz') ).
I have tried using --onefile, not using it. --add-data and --add-binary don't like it. --hidden-imports doesn't help. --debug=imports wasn't too useful, but the attached log was from --debug=all compilation.
Any thoughts on how to force pyinstaller to include nutation.npz into the built .exe so its there when its extracted/run?
import skyfield.nutationlib # PyInstaller PYZ
Traceback (most recent call last):
File "satvis.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\skyfield\api.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\skyfield\constellationlib.py", line 29, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\skyfield\timelib.py", line 14, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\skyfield\nutationlib.py", line 7, in <module>
File "site-packages\skyfield\functions.py", line 143, in load_bundled_npy
File "pkgutil.py", line 637, in get_data
File "c:\users\fox\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 471, in get_data
with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\fox\\AppData\\Local\\Temp\\_MEI89762\\skyfield\\data\\nutation.npz'
[44412] Failed to execute script satvis
You need to add a directory with skyfield data files (npz, npy, etc).
For example, if skyfield located in the virtual environment folder, you need the following pyinstaller call:
pyinstaller --onefile --add-data 'venv/Lib/site-packages/skyfield/data;skyfield/data' yourapp.py
In Skyfield's code, it looks like it thinks of that file as belonging to the package "skyfield":
data = get_data('skyfield', 'data/{0}'.format(filename))
But in Skyfield's setup.py, that file belongs to the subpackage skyfield.data instead:
package_data = {
'skyfield': ['documentation/*.rst'],
'skyfield.data': ['Leap_Second.dat', 'deltat.data', 'deltat.preds',
'*.npy', '*.npz'],
'skyfield.tests': ['data/*'],
},
If you have the ability to edit your local copy of Skyfield, try changing the above-quoted line of code from skyfield/functions.py so that it says:
data = get_data('skyfield.data', '{0}'.format(filename))
There is some chance that the change will fix the problem with PyInstaller. If it does, I will make the change officially to Skyfield’s code!
I was able to build a working "onefile" of myprog.exe on Win10 with
python 3.7.9
pyinstaller 4.0
skyfield 1.29
by building a spec file using the command
pyinstaller -F myprog.py
then in the spec file, changing the line
datas=[],
to
datas=[ ('C:\\Users\\Administrator\\Anaconda3\\pkgs\\skyfield-1.28-pyh9f0ad1d_0\\site-packages\\*', 'skyfield')],
The build command I used was
pyinstaller -clean myprog.spec
I don't believe Anaconda had anything to do with it, that's just where my installation has the skyfield package data. I did build it in a standard Python virtual environment however.
I am trying to run a voice program in Python 3.7.4 and with pyttsx library. But I've faced up with lots of problems while converting the file into an .exe file from .py file. Initially the program as executed in python runs fine. But when i converted the .py file to.exe using pyinstaller it gives me the following error while running :
File "site-packages\pyttsx3\__init__.py", line 20, in init
File "c:\users\s som\appdata\local\programs\python\python37-32\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "DesktopAi.py", line 22, in <module>
File "site-packages\pyttsx3\__init__.py", line 22, in init
File "site-packages\pyttsx3\engine.py", line 30, in __init__
File "site-packages\pyttsx3\driver.py", line 50, in __init__
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers'
[11180] Failed to execute script DesktopAi ```
You can try the following:
pyinstaller --hidden-import=pyttsx3.drivers DesktopAi.py
so I have been using Pyinstaller the last couple of months to package and distribute my applications as single exe files, however I recently made the switch from using Tkinter in my GUI apps to using PySide2 (QT5 Wrapper). The thing is, I'm not able to package those executables, as I'm getting the following error at runtime:
Exception: [Errno 2] No such file or directory: 'C:\\support\\signature\\loader.py'
Traceback (most recent call last):
File "pyscript", line 23, in bootstrap
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\support\\signature\\loader.py'
AttributeError: module 'signature_loader' has no attribute 'pyside_type_init'
SystemError: could not initialize part 2
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "pkg_resources\__init__.py", line 33, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "platform.py", line 116, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "subprocess.py", line 50, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "signal.py", line 45, in <module>
File "c:\program files\python37\lib\functools.py", line 54, in update_wrapper
value = getattr(wrapped, attr)
SystemError: <method-wrapper '__get__' of getset_descriptor object at 0x0000023A7ACE88B8> returned a result with an error set
[9240] Failed to execute script pyi_rth_pkgres
The package should consist of one .py file, one .uic QT file and a SQLite3 .db .
I have tried packaging with Pyinstaller in several ways, however the same exception arises when trying to execute the application.
I'm using Python 3.7.2, Pyinstaller 3.4, PySide 5.12.1 and peewee 3.9.2 .
Any help is greatly appreciated.
The following worked for me:
1. uninstalled pyinstaller and installed the developer version from git (but didn't change anything so far - maybe that's not necessary)
2. typed pyinstaller -v example.pyw
3. used the returned value from 2 as hidden import. In my case pyinstaller --hidden-import=4.0.dev0+869062597f example.pyw