No module named "PyQt5" found when using pyinstaller to create exe - python

I'm trying to create an .exe from my .py file. I'm using Pycharm with Python 3.7, PyQt5, and on windows. Every time I run the command, it seems to work and produces the directory/file, but when I run the file, it immediately crashes. When I ran it with CMD, it says "no module found named PyQt5".
I've looked through just about everything, and most people's solutions just don't seem to work with mine for some reason. I've tried adding PyQt5 to hiddenImports, I've tried adding the bin folder to PyQt from the venv to the path. I've also tried adding pyqt5.uic because someone said that might work.
Here's my command I'm running right now:
pyinstaller -y -p C:\Users\Velox\Downloads\Project\Lib\site-packages\PyQt5\Qt\bin --hidden-import PyQt5 "app.py"
Here's the exact error:
Traceback (most recent call last):
File "app.py", line 6, in <module>
ModuleNotFoundError: No module named "PyQt5"
[7112] Failed to execute script app

Related

Pyinstaller .exe file giving me "no module found cryptography" error in the console [duplicate]

This question already has answers here:
ModuleNotFoundError: No module named 'cryptography'
(3 answers)
Closed last month.
I wrote one program in python on my Linux virtual machine, and converted it to .exe using pyinstaller, but the console on my windows VM gives me this error:
Traceback (most recent call last):
File "python file.py", line 2, in <module>
ModuleNotFoundError: No module named 'cryptography'
[2224] Failed to execute script 'python file' due to unhandled exception
I usually always solve such problems myself, but here I’ve just been suffering with this program for 3 months and I can’t make out this problem.
in pyinstaller (autopytoexe) i have this command to convert my .py to exe
pyinstaller --noconfirm --onefile --console --hidden-import "cryptography" "C:/Users/user/Desktop/python file.py"
Other users on the internet they write that
--hidden-import "cryptography"
should have solved the problem, but that didn't help either.
and in the python code, I also wrote this at the start of the file
import os
import cryptography
import cryptography.fernet
from cryptography.fernet import Fernet
How about directly copy from your environment?
first, dont use onefile option. And copy the 'cryptography' folder from your python environment to your dist folder.
Fixed by doing pip install cryptography.

No Module Named 'apscheduler' Error When Running the .exe file. --hidden-file command Doesn't Work

I've recently created an .exe file of my program with pyinstaller using this code:
pyinstaller --onefile 'myprogram.py'
This worked for some other programs but when I ran this .exe file
Traceback (most recent call last):
File "myprogram.py", line 3, in
ModuleNotFoundError: No module named 'apscheduler'
[18908] Failed to execute script myprogram
When searching through internet, I found hidden import command and tried it using this code but it gave the same error message:
pyinstaller --onefile --hidden-import=apscheduler 'myprogram.py'
I don't know if it's related to the problem but I think it's worth noting that the import command of APscheduler looks like this:
from apscheduler.schedulers.blocking import BlockingScheduler
Is there anyway I can fix this issue quickly?
Pyinstaller version:4.3
Apscheduler version: 3.7.0

"ImportError: DLL load failed while importing" while using PyInstaller

I'm trying to package a PyQt5 Python app using PyInstaller.
When I package it normally, without using UPX, it works fine. When I start using UPX, though, I start running into a lot of problems. I have to use --upx-exclude "vcruntime140.dll" to keep that file from being corrupted.
Then, I run into this problem.
Traceback (most recent call last):
File "main.py", line 3, in <module>
ImportError: DLL load failed while importing QtWidgets: The parameter is incorrect.
[26400] Failed to execute script main
Here's the beginning of main.py:
import sys
import PyQt5
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon
I read here (similar problem, I think) that I might be having trouble with hidden imports, so I run the PyInstaller command with --hidden-import "PyQt5", then with --hidden-import "PyQt5" --hidden-import "QtWidgets". But I keep getting the same error, DLL load failed while importing QTWidgets.
The full PyInstaller command I'm using is:
pyinstaller -n "[exe name]" -i "[icon file path].ico" --upx-dir "[path to UPX]\upx-3.96-win64" --upx-exclude "vcruntime140.dll" --hidden-import "PyQt5" --hidden-import "QtWidgets" --clean main.py
What can I do to fix this error?
I had the exact same problem earlier this week.
I fixed it by disabling UPX entirely. You could go through adding more and more of the QT DLLs to the UPX exclude list to figure out which ones specifically it's corrupting if you still want to compress some of them, but for now I'm ok with just having it disabled entirely.
I tried many things - different versions of PyQT5, different versions of other libraries, none of that had any effect.
If you have a .spec file for folder based build, be sure to disable UPX in both the exe and coll sections.

How do you fix this error: "ImportError: DLL load failed: The specified module could not be found." using PyQt5

I am currently using Python 3.6.8 and PyQt5. My program was working fine but after a Windows Update, everything stopped working.
Here is the error:
Traceback (most recent call last):
File "main.py", line 10, in <module>
from PyQt5 import QtWidgets, QtCore, QtGui
ImportError: DLL load failed: The specified module could not be found.
I fixed this error by running the following command on my command prompt:
pip install pyqt5-tools
It looks like the environment variables have become corrupt after the update. In the simplest case, it should just be
Adding your DLL location of python, for example,
(C:\Program Files\Python35\DLLs)
in the path in Environment variables. You can also see some others possible solutions here
Change your interpreter you are using in the IDE i.e. use the same version of python which is running in your cmd prompt. This solved my error.

ModuleNotFoundError: No module named 'bayesnet'

I'm trying to use the OpenBayes module, but the problems start from the very first step :'(
When I try to import from OpenBayes
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Мари\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenBayes\__init__.py", line 7, in <module>
from bayesnet import *
ModuleNotFoundError: No module named 'bayesnet'
UPD: While installing (from .exe file) for py2 i gor error: "could not set a key value" (not a python error, but in dialog window)
I tried using pip install from console, but still get errors there.
Command "python setup.py egg_info" failed with error code 1 in C:\Users\CD3B~1\AppData\Local\Temp\pip-build-m4nnwa4o\OpenBayes\
Also not sure which py (2 or 3) is used when i type a command from console(
(Sorry for all that stupis questions)
You should
from OpenBayes import *
or
from OpenBayes import BNet
Here is an example demonstrating it's usage:
https://github.com/willasaywhat/OpenBayes-Fork/blob/master/Examples/bn_asia.py
I had the same problem and I created a directory with the same name as the root folder (within the root folder). Python then referred Its import calls to the src directory and not the folder. I also changed the python interpreter to a virtual (anaconda.exe), as the python install did not contain many of the modules that were being called by the application (flask, etc)
It's a weird workaround, but it worked for me. Hope this helps

Categories

Resources