ImportError: DLL load failed while importing win32print - python

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.

Related

Error when using winshell module: No module named 'win32'

import winshell
r = list(winshell.recycle_bin())
for index, value in enumerate(r):
print(index, value.original_filename())
This is the simple script I wrote, but when I try running it (or antyhing else that uses winshell) I get this error:
ModuleNotFoundError: No module named 'win32'
And when I try running pip install win32 I get another error:
ERROR: Could not find a version that satisfies the requirement win32 (from versions: none)
ERROR: No matching distribution found for win32
So now I'm even more confused. Why does winshell need a different module? That module doesn't even exist. Is it fine if I use some different module than the non-existent win32? If so which one? What am I supposed to do now?
First, you have to execute the script inside the Scripts directory, the pywin32_postinstall.py. Let’s say your Python directory is C:\python3, just follow the code below.
cd C:\python3
python Scripts/pywin32_postinstall.py -install
After that, the installation will drop the DLL files under the C:\Windows\System32. You need to move those two files ( pythoncom310.dll and pywintypes310.dll) to C:\python3\Lib\site-packages\win32 directory.
After that, you need to edit the python310._pth that you can find inside the Python installation folder. Then make the following changes:
Lib/site-packages
Lib/site-packages/win32
Lib/site-packages/win32/lib
Lib/site-packages/pythonwin
python310.zip
#Uncomment to run site.main() automatically
#import site
Save and try running your code again.
Troubleshoot
If you still get an error saying “ImportError: DLL load failed while importing win32api: The specified module could not be found.”, make sure you have copied the two dll files to Lib\site-packages\win32 directory.
PythonWin32Api

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.

How can I avoid Pyinstaller import win32clipboard error?

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.

ImportError: DLL load failed: The specified module could not be found _ on a different machine (pyinstaller)

I was able to get exe file from py using pyinstaller.
I used the following code:
pyinstaller -y -F --additional-hooks-dir=. --add-binary ibm_db_dlls;.\ibm_db_dlls Data_QC_Ver1.py
this work fine on my laptop, however when trying it on a different machine I get the following error:

Script only works in Python installed directory

I have this script which read bar codes from images.
from PIL import Image
import zbar
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
pil = Image.open('zbartest2.png').convert('L')
width, height = pil.size
raw = pil.tostring()
image = zbar.Image(width, height, 'Y800', raw)
scanner.scan(image)
for symbol in image:
print 'decoded', symbol.type, 'symbol', '"%s"' % symbol.data
del(image)
When i put this script in python main directory which is C:\Python27 it works without any problem.
However, when i put this script outside of main directory such as C:\myscript, it gives me error saying that import zbar - module The specified module could not be found.
What is causing the problem?
I am using Python 2.7 32bits on windows Xp 32bits SP3
EDIT:
I am executing it from the IDLE window by using run module command (F5)
;full traceback
Traceback (most recent call last):
File "C:\myscript\test.py", line 2, in <module>
import zbar
ImportError: DLL load failed: The specified module could not be found.
when i type in import zbar; print zbar.__file__
i get the following msg
C:\Python27\lib\site-packages\zbar.pyd
It seems the dll is in c:\Python27 but c:\Python27 is not in the search path. Try the adding
import sys
sys.path.append("C:\Python2.7")
to your code before importing zbar.
If works correctly, then you have to configure your python's search paths in order to add C:\Python27. I work on linux, sorry I can't help you to do that on Windows.
EDIT: Well, I don't like write in an answer that I don't know how to do something. So I do some research looking for some doc that help me figure out what your problem is. And found it here importing PYD files.
Make sure you have all the files that you are importing in the same directory as this script

Categories

Resources