I use pyinstaller to package my python program into an executable program(exe).
my programs versions:
Pyinstaller :3.3.1
Python :3.6.1
Windows:10-10.0.16299-SP0
I can run the data_processing_gui.py file with the command "python data_processing_gui.py" in my command-line window without any errors.
I used this command to package my python program (which its name is data_processing_gui.py):
pyinstaller -F -p C:\Users\fanyu\Anaconda3\Lib;C:\Users\fanyu\Anaconda3\Lib\site-packages;C:\Users\fanyu\Anaconda3\Lib\site-packages\PyQt5\Qt\bin;C:\Users\fanyu\Anaconda3\Lib\site-packages\pydicom;C:\Users\fanyu\Anaconda3\Lib\site-packages\radiomics;C:\Users\fanyu\Anaconda3\Lib\site-packages\pywt;C:\Users\fanyu\Anaconda3\Lib\site-packages\pywt\_extensions;C:\Users\fanyu\Anaconda3\Lib\site-packages\tensorflow;C:\Users\fanyu\Anaconda3\Lib\site-packages\SimpleITK;C:\Users\fanyu\Anaconda3\Lib\site-packages\PIL;C:\Users\fanyu\Anaconda3\Lib\site-packages\pandas;C:\Users\fanyu\Anaconda3\Lib\site-packages\nrrd;C:\Users\fanyu\Anaconda3\Lib\site-packages\numpy -i C:\Users\fanyu\Desktop\work\package\image\doctor.ico data_processing_gui.py
There is no error when I run code above in windows' command-line window, but when I run the target program(data_progressing_gui.exe), there is a ModuleNotFoundError, and the error information is:
Traceback (most recent call last): File "data_processing_gui.py",
line 12, in File
"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packages\radiomics_init_.py", line 15, in File
"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packages\radiomics\imageoperations.py", line 6, in
File
"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packages\pywt_init_.py", line 17, in File
"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packages\pywt_functions.py", line 17, in File
"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
line 714, in load_module
module = loader.load_module(fullname) File "pywt/_extensions/_pywt.pyx", line 1, in init pywt._extensions._pywt
(pywt_extensions_pywt.c:31281) ModuleNotFoundError: No module named
'pywt._extensions._cwt' [7564] Failed to execute script
data_processing_gui
It seems like the program can't find the specified package path (pywt._extensions._cwt), however, I've added the path in the pyinstaller's parameter list.
At first, I thought maybe there was something wrong with my pyinstaller, so I tried to reinstall it. Then I write a simple python program to test it, it runs correctly.
I've tried a lot but just can't solve it, so I am here to ask for help,I will appreciate it if anyone can give me any advice.
I find a solution for my problem in the answers to the following question ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'
I can't explain why but it does solve my problem.
The solution is:
After generating the ".spec" file using pyinstaller,add the missing module into the ".spec" file at "hiddenimport=[]",like this:
hiddenimport=["pywt","pywt._estentions._cwt"]
Then use this file to generate your exe file:
pyinstaller my.spec
Related
I have used pyinstaller many times before but I have never faced such issues
I am facing issues while converting .py to .exe using pyinstaller
What I have tried
I have installed pythonnet and opened the directory where pythonnet is stored but i could not find any dll file
I am using the following command
PyInstaller app.py --noconsole --icon=./images/Source.ico
entire Traceback
Traceback (most recent call last):
File "c:\Users\ADMIN.DESKTOP-USLQ9P3\Desktop\jarvis\setup.py", line 3, in <module>
PyInstaller.__main__.run([
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 725, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 672, in build
exec(code, spec_namespace)
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\Desktop\jarvis\app.spec", line 6, in <module>
a = Analysis(['app.py'],
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
self.__postinit__()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 420, in assemble
self.graph.process_post_graph_hooks()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks
module_hook.post_graph()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph
self._load_hook_module()
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module
self._hook_module = importlib_load_source(
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\PyInstaller\compat.py", line 598, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 462, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 962, in load_module
File "<frozen importlib._bootstrap_external>", line 787, in load_module
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\ADMIN.DESKTOP-USLQ9P3\AppData\Roaming\Python\Python38\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-clr.py", line 40, in <module>
raise Exception(pyruntime + ' not found')
Exception: Python.Runtime not found
I have also install pythonnet but it is still not working neither can I find the dll
This is not a direct answer to your question, but I have had a lot of issues with pyinstaller myself in the past year. At this point I have the process perfected that I almost never have issues anymore. The key for me has been:
Do not use virtual environments (venv). I use a separate older computer specifically for pyinstaller. The computer only has basic python, pycharm and the libraries I need for my build installed to site packages. I install everything globally. I remove libraries I do not need.
If a library causes problems like you describe, try installing an older versio of said library.
To follow up:
Using pycharm does not work or pycharm in general does not work?
What I would recommend you do is what I do on a fresh computer:
Make sure you know which libraries your project requires. You could generate a requirements file: Automatically create requirements.txt
Uninstall python / anaconda from your computer completely incl all libs.
Reinstall python (not anaconda as it has way to many libraries) and click yes if installer asks you to add to path. Install pycharm community edition if you do not have it.
Install pyinstaller and other libs you need, but install them globally! I recommend using pycharm. Settings>yourproject>python interpreter>little plus icon>libraries you need. IMPORTANT: CHOOSE TO INSTALL TO SITE PACKAGE DIRECTORY:
Go to terminal in pycharm and type: pyinstaller --onefile my_python_file.py
You should now get an .exe file. in a dist folder in the directory of your file.
NOTE: the above should not be necessary and pyinstaller can work with virtual environments, but I have found it to be the most reliable way to use pyinstaller.
Try installing py2exe. This program also bundles python programs into .exe files, and I have used it for one of my games. To install this program, simply type into the command line:
python -m pip install py2exe
For more resources on py2exe, check out these links:
http://www.py2exe.org/
https://github.com/py2exe/py2exe
You should reinstall python and add it to your path, that might help you. There are lot of videos online you can refer to.
Recently, I have installed pyinstaller 4.2.
This is the error I get after running the script from cmd:
Traceback (most recent call last):
File "Keylogger.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 359, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 359, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[41576] Failed to execute script Keylogger
The command I used to convert to .exe is "pyinstaller --onefile Keylogger.exe"
I am a beginner coder so I don't understand what the error actually is. Can anyone pls help me? Thank you.
Try running the below command.
pyinstaller --onefile Keylogger.py
Your python file ends with .py extension.
There was a problem with exe conversion using the pyinstaller.
Traceback (most recent call last):
File "Find.py", line 1, in <module>
File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\tensorflow\__init__.py", line 98, in <module>
File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
File "lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
File "lib\site-packages\tensorflow\__init__.py", line 44, in _load
File "importlib\__init__.py", line 126, in import_module
File "c:\users\hsk15\python_project\javaproject\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
ImportError: cannot import name 'pywrap_tensorflow'
[20188] Failed to execute script Find
this error.. i can find problem
why can not import pywrap_tensorflow? and what is pywrap_tensorflow?
Pywrap tensorflow is a wrapper for TensorFlow SWIG-generated bindings.
How to use pyinstaller:
First, install the pyinstaller using command prompt by executing
pip install pyinstaller:
Run this line in cmd:
pip install auto-py-to-exe
To open the application run this line in cmd:
auto-py-to-exe
There are few main options you need to choose:
Pick your .py file
Pick "One Directory" or "One File" option
Pick additional files
Then, open the application run this line in cmd, enter the command
pyinstaller filename.py replace the filename with your python code file.
First; create a virtual environment. To do this, you should run this on cmd:
pip install virtualenv
And then, run this:
python -m venv VIRTUAL_ENVIRONMENT'S_NAME
VIRTUAL_ENVIRONMENT'S_NAME/Scripts/activate
pip install pyinstaller
And then, download all the libraries that you use. For example:
pip install requests
pip install datetime
Move your code file to:
VIRTUAL_ENVIRONMENT'S_NAME/Scripts
Now, you can convert it using:
pyinstaller --onefile PYTHON_FILE'S_NAME
I want to transform a simple .py code into .exe using PyInstaller, the program works fine with python, but when I transform it into .exe using PyInstaller, it returns the error:
ModuleNotFoundError: No module named numpy.core._dtype.ctypes
I tried installing the ctypes module, but the same error happenened.
How can I fix this error?
.py code:
import numpy
input("Worked")
cmd output:
C:\Users\enzo\Desktop\Compilando\dist\iaf>iaf.exe
Traceback (most recent call last):
File "iaf.py", line 1, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\__init__.py", line 151, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\ctypeslib.py", line 369, in <module>
File "site-packages\numpy\ctypeslib.py", line 358, in _get_typecodes
File "site-packages\numpy\ctypeslib.py", line 358, in <dictcomp>
ModuleNotFoundError: No module named 'numpy.core._dtype_ctypes'
[2872] Failed to execute script iaf
after I added to the beginning of the code:
import numpy.core._dtype_ctypes
my code works
spied on KmolYuan
As an alternative solution, you can downgrade your numpy package via
python -m pip install numpy==1.15.0
as there seems to be a problem for pyinstaller using the current numpy release (1.16.0).
I have a fully working Python program that uses the following imports:
import json
import requests
from natsort import natsorted
However, when I try to compile it to an executable using PyInstaller, I get the following errors:
Note: May not be perfect, as it was captured by my reaction times and a screenshot:
File "site-packages\requests\packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "huepy3.py", line 2, in <module>
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\__init__.py", line 63, in <module>
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\utils.py", line 24, in <module>
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\_internal_utils.py", line 11, in <module>
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\compat.py", line 11, in <module>
File "c:\users\andrew\appdata\local\programs\python\python35-32\lib\site-packages\PyInstaller\loader\pyimodo3_importer
py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\requests\packages\__init__.py", line 29, in <module>
ImportError: No module named 'urllib3'
Failed to execute script huepy3
I read the error, and tried to import urllib3 in my code as well. That returned the same errors as well. I'm thinking it's down to the location of urllib3 in relation to requests, but how can I solve this? I read online about FileDialog, and again it returned the same error.
Any pointers on this would be much appreciated.
Edit: It's not just the queue import problem, it's more of how to change the paths the library requests is trying to import from and how pyinstaller is going to get those paths in the first instance.
Edit 2: Ok, maybe I should ask how PyInstaller compiles the dependencies it finds and where it stores them? I could then give it a shot myself.
Edit 3: Through hours of crawling the web I believe I might be after hidden imports. How do those works for getting urllib3 in?
You can either:
update the spec file manually to include urllib3
or
run pyinstaller with the argument --hidden-import=urllib3