I wrote a code with pyqt5 pandas sqlalchemy pyodbc libraries
but when I want to make an exe from my py file with pyinstaller I get this error:
in _load_hook_module
self._hook_module = importlib_load_source(
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\compat.py", line 632, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1029, in load_module
File "<frozen importlib._bootstrap_external>", line 854, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\hook-sqlalchemy.py", line 32, in <module>
dialects = eval(dialects.strip())
File "<string>", line 0
SyntaxError: unexpected EOF while parsing
I searched for about 2 hours bet I couldn't find any solution
if you need to see my code comment on it and I will update the question with my code that I want to make exe of
I finally get it to work
I was exploring about my error till I found this:
this
and there was a guy that said:
if you install asyncio externally and you use above 3.3 python version then uninstall asyncio using pip uninstall asyncio it's works for me because 3.4 and above version added this in python-core so no need to add externally asyncio
and what I have done actually: pip uninstall asyncio
and it works like a charm!!!!
Thank you all
I faced the same issue when generating an executable with pyinstaller, simply run this line before invoking pyinstaller.
pip uninstall asyncio
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 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 dont understand why pip is not installed with python (I had a check mark in installer).
py -m pip returns no module named pip
I have windows 7, python 3.7.4 installed to c:\python.
tried different versions of python however, when i try install pip with get-pip.py i get:
C:\Python>python get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 22308, in <module>
main()
File "get-pip.py", line 197, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip._internal
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 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\Temp\tmpx8wd2cnb\pip.zip\pip\_internal\__init__.py", line 40, in <mod
ule>
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 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
many same errors (cant posted all of it here)
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\Temp\tmpx8wd2cnb\pip.zip\pip\_vendor\requests\compat.py", line 64, 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 "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 859, in get_code
File "<frozen importlib._bootstrap_external>", line 917, in get_data
OSError: [Errno 9] Bad file descriptor
Will be grateful for answer.
You are probably facing this issue because when you are installing python in the scripts folder pip is not getting installed ,I was facing the same problem 2 weeks back , when I searched the official site of python I finally found my answer to this problem.
1)Firstly install python the way you were doing that.
2)Next step is to run this command in your terminal: python -m ensurepip --default-pip
3)After running this command pip will successfully get installed to your system , check your scripts folder you will find the pip file there.
I have downloaded pyocd and built it successfully. Now I am able to run the tool from command line from any location. However when try to run it using pexpect it shows following error:
Traceback (most recent call last):
File "c:\Users\elephant\AppData\Local\Programs\Python\Python37-32\Scripts\pyocd-script.py", line 6, in <module>
from pkg_resources import load_entry_point
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 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3086, in <module>
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3070, in _call_aside
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3099, in _initialize_master_working_set
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 574, in _build_master
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 892, in require
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 778, in resolve
pkg_resources.DistributionNotFound: The 'pyocd==0.14.1.dev277+dirty' distribution was not found and is required by the application
Please help to understand what is wrong and why it works from command line?
The problem was that I tried to spawn pyocd.exe and pexpect was not able to find the package.
I changed the line to python -m pyocd and it just works fine.
I am new in Python and mistakenly thought that exe is compiled code as the other exe files in Windows. However, it is just an instruction to run the package using Python.
I am working on MacOS and I am trying to use PyInstaller to circulate a script to some non tech colleagues. The script is imaginatively called script_V1.py and runs fine.
Up to now, I have had issues with PANDAS and SCIPY but they seem to be resolved with with the command
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas --hidden-import scipy._lib.messagestream script_V1.py
However, I am now getting a different error (I'll post the full error below)
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
I have tried the solution in a similar question on Stack Exchange:
Installation Issue with matplotlib Python
But I think that is actually a different problem with import statements not working within the script itself. In my case if I run the script as a .py script it works fine. Anyway adding the suggested file did not alter the error message. Im new to this and seem to be really struggling with PyInstaller (more than with python itself) so any help much appreciated.
The full error message is (I've added line breaks for clarity)
Traceback (most recent call last):
File "script_V1.py", line 5, in <module>
import matplotlib.pyplot as plt
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/matplotlib/pyplot.py", line 115, in <module>
File "site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
[2582] Failed to execute script script_V1
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
So the way I got this to work in the end was to force Matplotlib to use WebAGG and also install the 'tornado' package (which is needed for some reason).