How can I avoid Pyinstaller import win32clipboard error? - python

I use PyInstaller (Win 10) to create a text analyzing app. But though it works fine in Visual Studio Code, the exe file creates an error.
I use:
pyinstaller --onefile textanalyzer_02.py
But starting the exe file gives me the following error:
Traceback (most recent call last):
File "textanalyzer_02.py", line 2, in <module>
import win32clipboard
ImportError: DLL load failed while importing win32clipboard: Das angegebene Modul wurde nicht gefunden.
[7604] Failed to execute script textanalyzer_02
I tried also:
pyinstaller --onefile textanalyzer_02.py --hidden-import win32clipboard
But it didn't work either. Any ideas?

Came across this while having the same issue. Found a solution that worked for me. I imported pywintypes into my script before win32clipboard:
import pywintypes
import win32clipboard
After that, my compiled program ran again without any errors. Windows 10 / Python 3.8.6 / PyInstaller 4.0.

This worked for me . I found the two dll files in my python installation folder and simply copied them to \windows\system32
pywintypes39.dll
win32clipboard39.dll
Your file names vill vary with the version of python you have.

Related

PyInstaller SSL error with requests module - missing module ssl (_ssl)

In my python script, I use the requests module to call an API to GET and POST data.
Python environment: anaconda3, python 3.7 / packages: requests 2.24.0, pyinstaller 3.6, openssl 1.1.1h...
I have the following problem with the EXE-file generated by PyInstaller: When I run this file, I get the following error message. This error doesn't occur when I run my script from Python:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_certifi.py", line 13, in <module>
File "c:\programdata\anaconda3\envs\...\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "ssl.py", line 98, in <module>
ImportError: DLL load failed: The specified module could not be found.
[20188] Failed to execute script pyi_rth_certifi
If I follow to the excepted error lines (ssl.py):
import _ssl # if we can't import it, let the error propagate
Why can't ssl be imported?
I searched a long time in serveral post on SO but all these answers didn't help, ex.:
Python Requests throwing SSLError
Python Requests - How to use system ca-certificates (debian/ubuntu)?
Twilio Python Module Errors After Compiling
Fixing SSL certificate error in exe compiled with py2exe (or PyInstaller)
Does anyone have an idea how to fix this?
If you need more informations, please write a comment. THX
EDIT: (for Mooncrater's comment)
added Screenshot from python console, entered:
import _ssl
EDIT 2:
Tested "FIX" from SO Question:
Python SSL Import Error in PyInstaller generated executable
-> this didn't fix my problem
EDIT 3: Answer by cbolwerk
THX for your answer, this works!
Python 3.7 anaconda environment - import _ssl DLL load fail error
An additional fix is to install the latest OpenSSL Lib, I used 1.1.1h package in my python script, on my PC was installed an older version and that causes the error too.
cbolwerk's answer I tested on a PC where NO OpenSSL is installed and , as I wrote, it works!
If you can import ssl in the python within your environment, it means that the ssl module is probably inside your environment. This answer mentions the files you can look for inside your environment. They are either inside your env/Library/bin or env/DLLs. I think you have these installed, but pyinstaller doesn't recognize them. To make sure that pyinstaller knows these files, you can add them to datas. This can be edited in the command when building the .exe file or in the .spec file that is probably created when you have run this command once. This link may be useful there.
In short, add the paths of the DLLs I mentioned to the datas (or binaries inside .spec actually) so that they are recognized by pyinstaller.
So either run the command
pyinstaller --onedir --add-data libcrypto-1_1-x64.dll;. --add-data libssl-1_1-x64.dll;. myscript.py
or change your .spec to something like
datas = [('/path/to/libcrypto-1_1-x64.dll', '.'), ('/path/to/libssl-1_1-x64.dll', '.'),
(...) ]
...
a = Analysis(...,
datas=datas,
...)
...
and then run
pyinstaller --onedir myscript.spec
This fixed DLL issues for me at least.

ImportError: DLL load failed while importing win32print

I have the following code
from win32 import win32print
for p in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL, None, 1):
_, _, name, _ = p
print (name)
The code works.
I'm trying to create an exe file from it as follows:
cd C:\Users\xralf\AppData\Local\Programs\Python\Python38-32\Scripts
pyinstaller.exe --onefile C:\Users\xralf\Desktop\enumprinters.py
cd dist
enumprinters.exe
It writes the following error message:
ImportError: DLL load failed while importing win32print: The specified module could not be found.
How can I fix it?
There are three ways I know maybe can solve your problem:
Update your pyinstaller.
Update your pywin32.
Try to find what's the dll it needed.(In /build/name/warnname.txt).And use pyinstaller --add-binary 'the_path_of_dll:.' myscript.py
If you are using python 3.8,Please use the old version.I heard that pyinstaller worked not very well in python 3.8.

Error message using pyinstaller

I am trying to convert a script into an exe using pyinstaller and Python3.70 (on Windows 10)
When I run the command
pyinstaller --onefile myfile.py
The program runs fine, except some warnings about libcrypto etc..
But when I try to run the exe file found in the dist folder I get this error message:
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'
Current thread 0x00002afc (most recent call first):
Try down-grading to Python 3.6, it seems there are issues with Pyinstaller and Python 3.7 that have not yet been addressed. As per Pyinstaller:
PyInstaller works with Python 2.7 and 3.3—3.6

python opencv dll load failed Missing environment variables?

I want to use Blender 2.72b with OpenCV, so I had to build it for Python3 (I have 3.4.2 installed since Blender is using that too). I'm working on Win7 64bit, so I used a 64bit version of Python and NumPy (Blender too of course). For OpenCV I used 3.0.0-beta.
For building I used CMake 2.8 and Visual Studio 2010 Professional (since I have a student-license > Visual Studio 10 Win64 in CMake).
I followed these instructions (lower ones), modified for python3.
These are my folders:
Target build-folder for CMake (OpenCV.sln executed and build in here too of course):
C:\Users\Gunnar\Desktop\build\
OpenCV-source-folder:
C:\Users\Gunnar\Downloads\opencv\sources\
Python installed here:
C:\Python34\
The build went fine, I adjusted the following before generating with CMake (python2 left blank):
PYTHON3_EXECUTABLE -> C:/Python34/python.exe
PYTHON3_INCLUDE_DIR -> C:/Python34/include
PYTHON3_LIBRARY -> C:/Python34/libs/python34.lib
PYTHON3_NUMPY_INCLUDE_DIRS -> C:/Python34/Lib/site-packages/numpy/core/include
PYTHON3_PACKAGES_PATH -> C:/Python34/Lib/site-packages
BUILD_opencv_python3 -> true
The build-folder has a cv2.pyd at
C:\Users\Gunnar\Desktop\build\lib\Release\
The cv2.pyd got copied to
C:\Python34\Lib\site-packages\
automatically and I copied it to
M:\Programme\blender-2.72b-windows64\2.72\python\lib\site-packages\
If I now open the python IDLE, I get the following error (same in Blender of course):
>>> import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
(in english: DLL load failed: Module not found.)
I'm assuming that I'm missing environment variables (from what I've found googling for it).
Looking into them I have no corresponding entry for PATH and no PYTHONPATH.
My problem now is that I don't know what I need to set there. I never really had to change something in there and I don't know what exactly is needed.
If more information are needed let me know.
EDIT:
I got i working now. I'm not quite sure, which one it did in the end, but I first used
cmd > setx -m OPENCV_DIR C:\Users\Gunnar\Desktop\build
and than edited the PATH-variable with these:
C:\Users\Gunnar\Desktop\build;
C:\Users\Gunnar\Desktop\build\lib\Release;
C:\Users\Gunnar\Desktop\build\x64\Release;
C:\Users\Gunnar\Desktop\build\bin\Release
And right now it works even though I removed all of them...

pycairo "ImportError: DLL load failed: The specified module could not be found." even after DLLs installed

I'm following the pycairo installation instructions here :
http://www.cs.rhul.ac.uk/home/tamas/development/igraph/tutorial/install.html
to install pycairo for use with igraph.
However, even after running the installer and unzipping/copying all DLL's into the site-packages cairo directory according to the instructions, I still get the following error:
>>> import cairo
Traceback (most recent call last):
File "", line 1, in
File "c:\Python26\lib\site-packages\cairo__init__.py", line 1, in
from _cairo import *
ImportError: DLL load failed: The specified module could not be found.
>>>
I am running python 2.6.6 under Windows 7.
Any ideas?
Open _cairo.pyd in Dependency Walker and figure out what it's missing.
I kinda solved the problem installing the Gtk-Bundle for Windows, wich had the third party dll dependencies.
(I did a dirty solution by pasting the dlls directly into c:/Python27/lib/dist-packages/cairo, because I am not used to Windows anymore and don't know for sure what is the expected place for the dlls to go.)
But my scripts started to work at last.

Categories

Resources