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

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.

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

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.

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

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

Issues with pyinstaller and pyproj

I'm trying to do an standalone application with pyinstaller. The executable has just build fine, but when I´m trying to do some operations with functions integrated on library pyproj, the executable crashes.
The script runs fine on Pycharm, so I think that the problem is that pyinstaller is not linking with some kind of library of pyproj.
May I have to do something special with spec file or another thing to specify pyproj on the standalone application built with pyinstaller?
This is the error that Ihave obtained:
Traceback (most recent call last): File "<string>", line 6, in
<module> File "C:\pyproj\build\main\out00-PYZ.pyz\pyproj", line 343,
in __new__ File "_proj.pyx", line 85, in _proj.Proj.__cinit__
(_proj.c:1190)
RuntimeError: no system list, errno: 2
This is my "main.py"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pyproj
print pyproj.__version__
p=pyproj.Proj(init='EPSG:4326')
Thanks in advance
The problem is that when using pyproj with PyInstaller, pyproj can not find the data files that are in the library folder.
The solution is to create a hook file, which will specify where the data files, so you can link them with our executable.
hook-pyproj.py
from PyInstaller.hooks.hookutils import collect_data_files
datas = collect_data_files('pyproj')
The hook file can be located on "hooks" folder on Pyinstaller installation or using the order --additional-hooks-dir, specifying a folder in which will be located "hook-pyproj.py"
Just threading on the previous answer, since 2014 there has been some refactoring on PyInstaller and here is the correct import line for the hook file above :
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('pyproj')
from PyInstaller.hooks.hookutils import collect_data_files
datas = collect_data_files('pyproj')
This didn't worked for me. There were some errors in the executable again.
But I found in another thread that the problem can be solved with this:
from mpl_toolkits.basemap import pyproj as pyproj
pyinstaller seem to have problems to integrate the pyproj module itself, but basemap includes pyproj and is not ignored by pyinstaller.
Just for update

Categories

Resources