Can't load pywin32 library win32gui
Asked Answered
K

9

6

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?

Kerge answered 18/10, 2010 at 2:0 Comment(0)
H
3

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.

Heida answered 18/10, 2010 at 4:15 Comment(1)
Well, a missing DLL was fairly obvious :p just wasn't sure about which one :) depends solved the issue, working fine now. Thanks for the tip :)Kerge
F
14

This works:

import pywintypes
#import pythoncom # Uncomment this if some other DLL load will fail
import win32gui
Fudge answered 21/4, 2011 at 10:31 Comment(2)
I don't think this is exactly what the question was asking for, but it fixed my problem. I had win32gui installed on my system, but was trying to pack everything up with cx_freeze. Just including win32gui worked locally, but not on other systems--including pywintypes forced cx_freeze to include the correct DLL.Schuyler
This pointed me in the right direction; to get pywintypes to import I then had to copy the dlls in my virtualenv from Lib\site-packages\pywin32_system32 to Lib\site-packages\win32\libAigneis
L
6

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

Lundin answered 4/12, 2013 at 5:45 Comment(0)
H
3

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.

Heida answered 18/10, 2010 at 4:15 Comment(1)
Well, a missing DLL was fairly obvious :p just wasn't sure about which one :) depends solved the issue, working fine now. Thanks for the tip :)Kerge
F
3

I tried to only "copy" pywin32 package once instead of installing it and it works well.

what i've done is :

  1. Copy over all the related packages to site-packages folder
  2. Copy pythoncom25.dll & pywintypes25.dll to c:\windows\system32 folder (you might need to change to version&system path)

Hope it helps

Firecrest answered 30/3, 2011 at 8:24 Comment(1)
Copying those two files helped ( they are in python install folder ).Collinsworth
R
3

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.

Ragwort answered 17/9, 2017 at 11:36 Comment(1)
You previously posted this exact same answer to another question. Please don't post identical answers to multiple questions. Pick the best question and post one good answer there, and then flag to close the other question(s) as duplicates. (I've already handled the duplication in this case.) If the questions are not duplicates, you must tailor your answers specifically to each question.Dorene
F
1

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

Fumigator answered 4/4, 2022 at 13:54 Comment(0)
D
0

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

Danyluk answered 23/11, 2016 at 9:57 Comment(0)
P
0

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

Perdomo answered 27/7, 2020 at 11:17 Comment(0)
B
0

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.

Boley answered 2/5, 2022 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.