Python 导入错误:没有名为 pywintypes 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18907889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named pywintypes
提问by Eden Pigram
I am working to make a small keylogger with Python, by using the pyHook, pythoncom and Pywin32 modules. Here is my code:
我正在使用 pyHook、pythoncom 和 Pywin32 模块使用 Python 制作一个小型键盘记录器。这是我的代码:
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?
我该如何解决这个错误?
回答by icktoofay
pywintypes
is part of the Python for Windows extensions, otherwise known as pywin32. You'll need to install that to get access to pywintypes
.
pywintypes
是Python for Windows 扩展的一部分,也称为 pywin32。您需要安装它才能访问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.
请注意,在撰写本文时,pywin32
的维护者并未将文件上传到 PyPI,因此您必须从http://pywin32.sf.net获取适当版本的安装程序。
回答by Mithilesh Gupta
pip install pypiwin32
worked for me
pip install pypiwin32
为我工作
回答by Abhishek D K
Just add pythoncom34.dll and pywintypes34.dll to your C:\Python34\
只需将 pythoncom34.dll 和 pywintypes34.dll 添加到您的 C:\Python34\
回答by trashvin
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.
我知道我的回答有点晚了,但只是遇到了这个问题。pywin32 和 pypiwin32 都安装在我的 virtualenv 上,我的应用程序在测试期间运行良好。当我运行 pyinstaller 来构建我的 exe 时,出现了这个错误。
Solution: I needed to install (through pip) pywin32 and pypiwin32 on my base python env ( not the virtualenv) for pyinstaller to build my exe.
解决方案:我需要在我的基础 python env(不是 virtualenv)上安装(通过 pip)pywin32 和 pypiwin32,以便 pyinstaller 构建我的 exe。
回答by Wizhi
For me it worked to copy the files (pythoncom38.dll and pywintypes38.dll) from:
对我来说,它可以从以下位置复制文件(pythoncom38.dll 和 pywintypes38.dll):
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