Can't transform a python program into exe - python

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).

Related

PyInstaller - when opening cant find _tkinter Module (required by PySimpleGui)

I have a quesetion. I made a Python App and wanted to distribute this to friends.
I used PySimpleGui for the GUI and when I open the .py App with Python it works fine. But when I package it with PyInstaller and then open it I get this message:
/Users/USERNAME/Documents/Dev/application/dist/APPLICATION  1 ✘  14:57:29 
Traceback (most recent call last):
File "stamp.py", line 5, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/__init__.py", line 2, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/PySimpleGUI.py", line 111, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "tkinter/__init__.py", line 37, in <module>
ModuleNotFoundError: No module named '_tkinter'
[53336] Failed to execute script 'APPLICATION' due to unhandled exception!
Im using MacOS with Big Sur 11.5, Python 3.9.6 (with Pyenv) and PyInstaller 4.5.1.
I already tried troubleshooting with:
Reinstalling PySimpleGui
Reinstalling tkinter
use "hidden imports" for both
...
but nothing works...
Can I bundle tkinter with the application?

Py to exe pyinstaller import errors

Im trying to convert a single file python script/project into an exe using pyinstaller
Even thought pyinstaller converts the script the .exe will run and throw this
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[16676] Failed to execute script main
I'm stumped , through my trial and erroring i figured that when i replace pynput with a module like random the convertion works fine , but i need it to work with pynput
please help , thanks in advance!
Authors made some changes which i feel broke the reference.
so instead of package it is referring file.
- backend = backend(__package__)
+ backend = backend(__name__)
pls try to downgrade your package and check that your app still works.
pip install pynput==1.6.8
then your command like following would work.
pyinstaller --onefile build_pkg_for.py

I want to convert Python to exe that imported tensorflow

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

Using pyinstaller to package python program and there is a "NoModuleFoundError"

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

PyInstaller Hidden Imports

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

Categories

Resources