Pyinstaller error running script with pyzmq dependency - python

This is my first StackOverflow post!
I am running into issues creating a pyinstaller(v4.2) executable with a pyzmq (v22.0.2) dependency. I created an executable by running "pyinstaller main.py". The dist folder was created without errors but when I run the executable in the terminal, I see the error in quotes below.
I did a search for this kind of issue on StackOverflow and pyinstaller's documentation with no match to my exact problem. I saw mention of a .spec file for what seemed like similar issues, though I am not sure if this is the way to go since I am unclear what pyzmq.libs\.load_order is.
Does anyone know how to overcome this error or have good leads on what I may try?
"C:\Users\[redacted path]\dist\main>main.exe
Traceback (most recent call last):
File "main.py", line 1, 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 "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "zmq\__init__.py", line 19, in <module>
File "zmq\__init__.py", line 13, in _delvewheel_init_patch_0_0_9
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\[redacted path]\\dist\\main\\pyzmq.libs\\.load_order'
[4408] Failed to execute script main
C:\Users\[redacted path]\dist\main>"

I had the same problem and found this solution
Downgrade to 21.0.0 using pip install pyzmq==21.0.0
then you can run pyinstaller again and it will run perfectly fine.

Find a folder called 'pyzmq.libs' in your <local-python-path>\Lib\site-packages.
For example, I'm using Miniconda3 here, so I got this at C:\\Users\MyPC\Miniconda3\envs\my_env\Lib\site-packages
Then, copy this folder to your C:\\Users\\[redacted path]\\dist\\main folder, and re-try the executable.

Related

Cannot create .exe with pyinstaller from .py with torchaudio (CPU): AttributeError: '_OpNamespace' 'torchaudio' object has no attribute 'cuda_version'

I have a .py script that uses torchaudio (without GPU) to process some sound in Windows. To distribute it, I've used pyinstaller to turn it into a .exe. You can reproduce the issue with this simple script:
import torchaudio
import time
if __name__ == '__main__':
t = torchaudio.transforms
time.sleep(3)
print("Success")
This script correctly runs from a python console python test.py but I want to create a test.exe that works in Windows (without having python installed). I create test.exe by using pyinstaller: pyinstaller test.py. This creates a build/test folder with all the required dependencies (around 1GB). test.exe is located inside that folder but when I double click on it, it fails with the following error:
Traceback (most recent call last):
File "torch\_ops.py", line 501, in __getattr__
op, overload_names = torch._C._jit_get_operation(qualified_op_name)
RuntimeError: No such operator torchaudio::cuda_version
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.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 499, in exec_module
File "torchaudio\__init__.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 499, in exec_module
File "torchaudio\_extension.py", line 136, in <module>
File "torchaudio\_extension.py", line 121, in _check_cuda_version
File "torch\_ops.py", line 505, in __getattr__
raise AttributeError(
AttributeError: '_OpNamespace' 'torchaudio' object has no attribute 'cuda_version'
[11648] Failed to execute script 'test' due to unhandled exception!
The environment uses:
python==3.9.15
torch==1.13.0
six==1.15.0
numpy==1.22.4
scipy==1.6.0
sounddevice==0.4.5
torchaudio==0.13.0
pyinstaller==5.6.2
Note: I tried the same installing torch with cuda ending up with the same error and a build 4 times bigger.
I was able to make the script work. Here are the steps I took to get it to run.
Create a new empty directory and pasted your script in as main.py
py -m venv venv && venv\scripts\activate && py -m pip install --upgrade pip pyinstaller
pip install torchaudio==0.13.0 torch==1.13.0 numpy=1.22.4 sounddevice==0.4.5 six==1.15.0 scipy
pyinstaller -F main.py
Go into venv\Lib\site-packages and copy the entire torchaudio folder and paste it into the top level directory alongside venv and main.py
In main.spec set datas=[('./torchaudio','./torchaudio')]
pyinstaller main.spec
And after compiling the executable runs... it still gives off a few warnings, but it runs and prints the success message.

Pyinstaller speedtest convert to exe error; no module name "__builtin__"

I am trying to convert a program to an exe using pyinstaller. The program performs a hardware assessment of a user's computer to include running an internet speed test utilizing speedtest-cli. The program runs fine until I compile it at which point I receive the following error:
Traceback (most recent call last): File "speedtest.py", line 156, in <module> ModuleNotFoundError: No module named '__builtin__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "hw-assesment-tool.py", line 9, 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\pyimod03_importers.py", line 546, in exec_module File "speedtest.py", line 179, in <module> File "speedtest.py", line 166, in __init__ AttributeError: 'NullWriter' object has no attribute 'fileno'
I have tried upgrading and re-installing speedtest-cli and it has not corrected the issue.
P.S. Here is a screenshot of the error:
Compiled Python EXE error originating in Speedtest-cli
First you need to go to C:\Users\user\AppData\Local\Programs\Python\Python38\Lib\site-packages. Then find the speedtest.py and open it with Notepad or any other Text Editor.
Now you need to edit these lines of code
Line 156: to
import builtins
Line 158 : to
import builtins
Line 199: to
del builtins
To confirm, you can find for __builtin__ and replace it with builtins
__builtin__ was changed to builtins in Python 3. I pulled the speedtest-cli code from the repo and edited out the Python2 functionality and it worked fine.
I met same issue before, you need to modify the spec file: hiddenimports=['speedtest'], and build exe via spec file(type command: pyinstaller -F main.spec), It's work!

Streamlit distribution not found in pyinstaller executable program

I made a streamlit application to act as a front end for a forecasting program and then I created a pyinstaller executable file to run the application. The problem rises when I run the executable file, I get the following error: pkg_resources.DistributionNotFound: The 'streamlit' distribution was not found and is required by the application with this traceback:
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "/opt/anaconda3/envs/Python35/lib/python3.5/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/streamlit/__init__.py", line 75, in <module>
File "site-packages/pkg_resources/__init__.py", line 476, in get_distribution
File "site-packages/pkg_resources/__init__.py", line 352, in get_provider
File "site-packages/pkg_resources/__init__.py", line 895, in require
File "site-packages/pkg_resources/__init__.py", line 781, in resolve
pkg_resources.DistributionNotFound: The 'streamlit' distribution was not found and is required by the application
[48095] Failed to execute script main
The file was created with the following command: pyinstaller --onefile -w main.py
This was setup on macOS Catalina with python 3.5.6 within a Conda environment
If there are any details that I may have missed that would help with this, please let me know.
Looks like you need to add a hook file called hook-streamlit.py with the following contents
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('streamlit')
You also need to pass the --additional-hooks-dir flag to your pyinstaller command.
If you've placed the hook file in the same directory as your python script you can specify it like so
pyinstaller --onefile --additional-hooks-dir=. -w main.py

Python EEL and PyInstaller Issue

I've recently created a program using eel, in this program I use the module moviepy to split the audio and the video of a file.
But when I try to put the whole project into an .exe file with PyInstaller, the app won't work.
The command I used is: python -m eel main.py web
I tried compiling the program without moviepy (I simply removed the import from main.py) and it perfectly worked.
So the problem is clearly moviepy which is not imported from PyInstaller.
Now I'm asking if there's any way to add moviepy dependencies using PyInstaller?
PS: Starting the source file works perfectly, it doesn't start only after compiled with PyInstaller
EDIT:
When I start the compiled .exe file with cmd, it gives me this error:
Traceback (most recent call last):
File "main.py", line 4, 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\Lucad\AppData\Local\Programs\Python\Python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\moviepy\editor.py", line 84, in <module>
File "<string>", line 1, in <module>
AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'
[8740] Failed to execute script main
EDIT 2: FOUND A SOLUTION!
I read a thread where people say that moviepy has an error importing some modules, so all I had to do was modifying a file.
This is the link of the guide I followed: https://github.com/Zulko/moviepy/issues/591
Thanks to everybody answering me!
Did you try add moviepy explicitly to the path?
pyinstaller -y -D --name Whatever --clean --distpath="." -p "c:\Python37\Lib\site-packages\moviepy" yourpyfile.pyw

KeyError: 'kivy.garden.xpopup' when Installing Kivy Designer with Kivy3 and Python3 on MacOS

EDIT: As has been pointed out several times, this question looks like a duplicate of other questions about Kivy Designer. As I show in the bolded section below however, and in my other comments, the solutions listed for those other questions have not worked for me.
I am trying to install Kivy Designer on my mac and running into what seems to be a fairly common problem. Following the instructions on the installation page (and, as suggested there, replacing 'python' with 'kivy'), when I try to run kivy3 -m designer I get the following traceback:
Traceback (most recent call last):
File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Applications/Kivy3.app/Contents/Frameworks/python/3.6.5/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/*username*/kivy-designer/designer/__main__.py", line 3, in <module>
from designer.app import DesignerApp
File "/Users/*username*/kivy-designer/designer/app.py", line 14, in <module>
from designer.components.dialogs.add_file import AddFileDialog
File "/Users/*username*/kivy-designer/designer/components/dialogs/add_file.py", line 5, in <module>
from kivy.garden.xpopup.file import XFileOpen, XFolder
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
File "<frozen importlib._bootstrap>", line 628, in _load_backward_compatible
KeyError: 'kivy.garden.xpopup'
I have spent a long time looking for a solution for this. The most commonly suggested solution is garden install xpopup. When I run this, I get the message:
Garden package already installed in /Users/*username*/.kivy/garden/garden.xpopup
Use --upgrade to upgrade.
When I try running kivy3 -m designer again after this, I get the same KeyError. I have tried various other solutions suggested here:
Installing Kivy-designer (Attempted last solution listed, substituting 'xpopup' for 'filebrowser' where applicable)
Installation of Kivy Designer on Windows
(Attempted second solution listed, using kivy3 -m designer instead of python -m designer)
but none of these have worked for me.
Does anyone have a different solution that has worked for them?
Thank you!
Run
garden install xpopup
it will do the trick.

Categories