building with Pyinstaller not working on Mac OS Catalina - python-3.x

I have had some errors working while with pyinstaller for python 3. I am using Mac OS Catalina. please help me my issue.
print("Hello World")
I'm running the below pyinstaller
pyinstaller --log-level=DEBUG --clean --icon "/Users/projects/hello/build/noun_wooden_wheel_2216564_420.icns" --name hello_world --exclude-module='FixTk' --exclude-module='tcl' --exclude-module='tk' --exclude-module='_tkinter' --exclude-module='tkinter' --exclude-module='Tkinter' --exclude-module='pytest' --onefile -d all --windowed main.py
Here is the error I get after I run the output file
Error loading Python lib '/var/folders/q9/g1d15sw13q5cdspzvpq46mrr0000gn/T/_MEIgYpRBc/Python': dlopen: dlopen(/var/folders/q9/g1d15sw13q5cdspzvpq46mrr0000gn/T/_MEIgYpRBc/Python, 10): no suitable image found. Did find:
/var/folders/q9/g1d15sw13q5cdspzvpq46mrr0000gn/T/_MEIgYpRBc/Python: code signature invalid for '/var/folders/q9/g1d15sw13q5cdspzvpq46mrr0000gn/T/_MEIgYpRBc/Python'
/var/folders/q9/g1d15sw13q5cdspzvpq46mrr0000gn/T/_MEIgYpRBc/Python: stat() failed with errno=3
I'm not even able to run on the machine I built it on.

macOS does not understand one-file bundles, do not use the --onefile flag.

Related

How to freeze my Python code with PyInstaller when the exe says it miss some files?

I am using Python 3.7.9 with Pyinstaller 5.0.1
I am trying to freeze my code which uses pyshadow.
When I execute it from Pycharm it works fine.
When I execute the exe after I freezed the code, I get this error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\gauth\\AppData\\Local\\Temp\\_MEI233082\\pyshadow\\resources\\querySelector.js
This could be a common issue when your python code uses some specific module that needs some third files. In my case, it is about pyshadow missing a JS file.
So I add this file 'querySelector.js' in the freezing command:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --add-data "querySelector.js;." main.py
But I still get the same error.
Does anyone have any idea how to fix this issue?
Thanks to rokm. I get his help from the git forum of the PyInstaller developer (full details here: https://github.com/pyinstaller/pyinstaller/discussions/6905). I publish his answer here in case someone has the same issue.
I had to add the parameter:
--collect-data pyshadow
So my final command is:
pyinstaller --onefile -F --uac-admin --icon="icon_PhoneBot_256.ico" --clean --noconsole --collect-data pyshadow main.py
ANd it works like a charm!

No module named 'reportlab.graphics.barcode.code128' error when using xhtml2pdf

My code works fine when running from the terminal, but when I try to run it as an executable after compiling it, it gives me a No module named 'reportlab.graphics.barcode.code128' error. I tried uninstalling and installing it again but still outputs the same error. Any ideas?
I had the exact same issue. The code works perfectly fine. But when built and compiled, the executable doesn't work. The cause of the error is xhtml2pdf dynamically loading reportlab.graphics.barcode. The solution is to include the entire reportlab.graphics.barcode when building the executable.
In PyInstaller this can be done with:
pyinstaller --onefile --noconsole --collect-all reportlab.graphics.barcode script.py
In nuitka:
nuitka --onefile --windows-disable-console --include-package=reportlab.graphics.barcode --include-data-dir=path_to_reportlab\graphics\barcode=barcode script.py

Getting error when using pynput with pyinstaller

A friend of mine asked me to write him a program, and I used pynput to handle some of the inputs and other features. When I convert the program an executable with pyinstaller, launcing the executable gives me this error: File "site-packages\pynput\keyboard\__init__.py", line 31, in <module> File "site-packages\pynput\_util\__init__.py", line 82, in backend ImportError [11492] Failed to execute script friend_project
I have tried using the pyinstaller command pyinstaller --onefile friend_project.py, and also using auto-py-to-exe to run it.
Using pyinstaller with other modules like pygame or pyopengl gives me no error, but this one module does.
Running the script by it self with the python inturpeter works fine, but I would perfer to have it be an exe so I can give it to him with out him needing python to run it.
Please fall back to 1.6.8 version of pynput.
pip install pynput==1.6.8
If you are running Windows you need to add these parameters to the command line (for the first time, after that they will be included in the generated spec file).
--hidden-import "pynput.keyboard._win32" --hidden-import "pynput.mouse._win32"
For Linux, use:
--hidden-import "pynput.keyboard._xorg" --hidden-import "pynput.mouse._xorg"
More information can be found in this Github issue.

"Error loading Python lib" when trying to run a python script as an executable

I am hoping to turn my python3 script into a distributable application but I'm having trouble turning the script into an executable.
I've tried using
pyinstaller myscript.py
and
pyinstaller --onefile myscript.py
to create the .exe file, however both times I've tried the .exe after it has been created, it's produced this error or a very similar error:
[4129] Error loading Python lib
'/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python':
dlopen:
dlopen(/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python,
10): no suitable image found. Did find:
/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python:
code signature invalid for
'/var/folders/c9/r16n40jd14d9x5f__gb0p3t80000gp/T/_MEIyzoWbA/Python'
The script I'm trying to run doesn't involve any images but it uses selenium webdriver, I'm very new to python so I don't know if either of these things would be a problem.
I have also tried uninstalling python3.8 and installing python3.7.9 but this has not worked either.

PyInstaller to executable file in lunx, giving : error running upx -v?

I tried to get executable file using PyInstaller on Linux terminal but its throwing error running upx -v. I tried with both .py and .spec file but same error
Same process i tried on windows its worked fine.
I am using :
1. Python : 3.5.7
2. PyInstaller : 3.5.
For more details pleas find check below image
I used below command and its worked
pyinstaller myfile.py --upx-dir=..\upx391w -y --onefile

Resources