ModuleNotFoundError: 没有名为“win32api"的模块 [英] ModuleNotFoundError: No module named 'win32api'
问题描述
这是收到的错误:
Traceback (most recent call last):
File "C:/Users/Joe Martin/AppData/Local/Programs/Python/Python37/test.py", line 12, in <module>
import win32com.client
File "C:\Users\Joe Martin\AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ModuleNotFoundError: No module named 'win32api'
尝试导入 win32com.client 模块时出现此错误.
This error occurs when trying to import the win32com.client module.
尝试的解决方案:
- 全新擦除并安装 Python 3.7
pip install pypiwin32
pip install pywin32
- 运行 pywin32_postinstall.py
我找不到任何其他解决方案来解决此问题.
I cannot find any other solution for how to fix this issue.
推荐答案
这通常是因为安装包后没有附加 PythonPath
.检查文件夹下的文件--pywin32.pth
--\\PythonVersion\\Lib\\site-packages\\
.
This is usually because no PythonPath
is appended after the package is installed.
Check the file--pywin32.pth
under the folder--\\PythonVersion\\Lib\\site-packages\\
.
文件内容如下:
# .pth file for the PyWin32 extensions
win32
win32\lib
Pythonwin
# Entries needed for a "portable" installations, where the post_install script
# isn't run, which would normally copy the pywin32 core DLL files to either
# the top of the python directory.
# We just stick the source of these DLLs directly on the PATH.
import os;os.environ["PATH"]+=(';'+os.path.join(sitedir,"pywin32_system32"))
或者创建一个PYTHONPATH
环境变量,并将win32
和win32/lib
路径加入其中.
Or create a PYTHONPATH
environment variables, and append the win32
and win32/lib
path into it.
你也可以临时在项目中加入这两条Python路径:
You could also add these two paths to Python in project temporarily:
import sys
sys.path.append('\\PythonVersion\\lib\\site-packages\\win32')
sys.path.append('\\PythonVersion\\lib\\site-packages\\win32\\lib')
添加路径暂时有效.
这篇关于ModuleNotFoundError: 没有名为“win32api"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!