Can't load pywin32 library win32gui - python

I'm trying to use the win32gui module included with pywin32 but I can't get it working.
I have downloaded it, built it and everything seem to be located under site-packages, I've found win32gui.pyd at site-packages/win32/win32gui.pyd but when I try to import it I get:
import pyHook, win32gui
ImportError: DLL load failed: The specified module could not be found.
Do I need to move a dll somewhere? and if so, which one?

This works:
import pywintypes
#import pythoncom # Uncomment this if some other DLL load will fail
import win32gui

I had the same issue. I added the path where pywintypes34.dll to system path and it worked.
In my case it was C:\Python34\Lib\site-packages\pywin32_system32

My guess is that win32gui depends on some DLL that is not on your system. You can download depends and see what you're missing.
However my first attempt will be try installing pywin32 from the installer, not by building it.

First check that "pywin32" module is installed in your system or not. If not installed then install it first. http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
If the issue still persists then now for the /Lib/site-packages/pywin32_system32 and add this path to system library or add pythoncom35.dll and pywintypes35.dll to the directory which is added to a system path.

I tried to only "copy" pywin32 package once instead of installing it and it works well.
what i've done is :
Copy over all the related packages to site-packages folder
Copy pythoncom25.dll & pywintypes25.dll to c:\windows\system32 folder (you might need to change to version&system path)
Hope it helps

Oddly, this is still an issue 12 years later. I suddenly had the same problem - got a DLL not found error importing win32gui with pywin32 v303.
The answer by DSblizzard from 2011 solved the issue for me, and everything worked once I imported pywintypes prior to win32gui:
import pywintypes # Not used, but need it for win32gui to import correctly
import win32gui

Same problem, I installed from sourceforge and then I run the .exe as administrator.

I wanted a win32gui module for which I installed the pywin32 module still error " DLL load failed while importing win32gui: The specified module could not be found", I went to folder pywin32_system32 folder in my virtual environment and copied DLLs and pasted inside win32 folder.
worked for me

This seemed to be the missing piece for me:
python.exe Scripts/pywin32_postinstall.py -install
That should be run after doing a:
pip install pywin32
After running those two things, import win32gui started working for me.

Related

Failed to execute script pyi_rth_win32comgenpy after packing with pyinstaller

I'm trying to pack a script that contains these external imports:
import keyboards
import win32gui
from PIL import ImageGrab
import pytesseract
I have a virtual environment set up with PyCharm, so I make sure to add the site-packages directory to the -paths option when running pyinstaller.
I am at a loss for what to do now since this error has never been fully answered. Some other resources (here and here) say to simply uninstall and then reinstall all packages relating to win32. I did that, but it's still not successful. Any ideas?
After playing around with it for about an hour, I've come to a solution. I added --hidden-import "pywin32" to the pyinstaller command, and it worked! So if uninstalling and reinstalling doesn't work, try adding "pywin32" as a hidden import.

unable to import module pyautogui

I am working on OS X
Ive looked at many different threads and haven't found a solution. Maybe I haven't been installing things properly from the start either. I want to import the module pyautogui into my project but it is saying it can't find it. I did a pip install in terminal and in the pycharmterminal as well. I have found the file directory and verified that it is available. But yet I am still not able to access it in my project. On some of the threads I read something about init.py, do I need to put that in my project. If so is there code in that py file or do I just create a python file named init.py
On Mac OS and some Linux distros, you may need to type pip3 install package-name.

Use of installed libraries

A Python script starts with:
from pathlib import Path
import sqlite3
which I read as an initialization of Libraries needed to run the rest of the script. However if the following error is returned in the terminal:
ImportError: No module named pathlib
I am uncertain how to interpret this. One assumption is that the pathlib library is uninstalled. However on the local system Python 2.7 and Python 3.4 are installed (I believe one was system pre-installed).
How can a library be asserted to exist? In case it is missing, how can it be installed?
You have to install it first
pip install pathlib
And with that your code should work.

Python ImportError - Custom Module

I have installed a custom module (Twilio) using PIP, but when I try to import it, it will bring up:
ImportError: No module named 'twilio'
I'm running Windows 10 and Python 3.5. What am I missing? It seems to be an error with the paths. If it is, how do I set the paths?
Edit: I have my PYTHONHOME set to C:\Python33 and my PYTHONPATH set to C:Python33\Lib
First of all you need to check your package location.
pip show custom_package
Then check the system paths by
import sys
sys.path
If you dont' see your package path here, you can add it.
sys.path.append(custom_package_path)
If this doesn't work try reinstalling it. Or you can also install it with easy_install

no module named Pillow._imaging

when i try to
import Pillow.selftest
no problem.
but, as you can see,
import Pillow._imaging
raises a importerror. i have been trying to rename the c-module, move it to the Lib folder, importing other (.py) modules in same folder, which works. nothing seems to work, any idea why?
as you can see, im using windows 7, python 3.3 and the pillow fork of PIL
Which version of Pillow are you using? Neither the 1.1.7 or 2.0.0 have import Pillow._imaging as core within image.py.
It looks like you have copied the contents of the source archive into Lib without running setup.py, which will be necessary to compile the C modules. Try using the Windows installer available on PyPi

Categories