我正在使用Python 3.6.4和pip 18.0。我已经用pip成功安装了numpy和pywin32,但是当我尝试使用记事本将它们导入文件时,如下所示:
import numpy
import win32com.client
运行文件时出现以下错误:
Traceback (most recent call last):
File "C:\Users\Joshua\Desktop\Python\test.py", line 1, in <module>
import pandas
File "C:\Program Files\Python36\Lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
或
Traceback (most recent call last):
File "C:\Users\Joshua\Desktop\Python\test.py", line 1, in <module>
import win32com.client
File "C:\Program Files\Python36\Lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: No module named win32api
但是令人困惑和沮丧的是,如果我尝试直接在python解释器中导入这些模块,例如:
python.exe
>>> import numpy
>>> import win32com.client
没有错误,我可以使用这些模块的所有类和功能。
所有这些模块都位于我的Path和PYTHONPATH环境变量中引用的site-packages目录中:
PYTHONPATH=C:\Program Files\Python36\Scripts;C:\Program Files\Python36;C:\Program Files\Python36\Lib\site-packages;
Path=C:\Program Files\Python36\Scripts;C:\Program Files\Python36;C:\Program Files\Python36\Lib\site-packages
并且我可以确认sys.path属性中列出了site-packages目录:
>>> import sys
>>> print("\n".join(sys.path))
C:\Program Files\Python36\Scripts
C:\Program Files\Python36
C:\Program Files\Python36\Lib\site-packages
C:\Users\Joshua\Desktop\Python
C:\Program Files\Python36\python36.zip
C:\Program Files\Python36\DLLs
C:\Program Files\Python36\lib
C:\Program Files\Python36\lib\site-packages\win32
C:\Program Files\Python36\lib\site-packages\win32\lib
C:\Program Files\Python36\lib\site-packages\Pythonwin
>>>
我为错是茫然...