我将 Python 2 和 Python 3 安装在不同的目录中,但我遇到了这个错误,因为当我使用命令 pip install pandas 时,它在我使用 Python 3 时将 Pandas 安装在 Python 2 目录中。
所以我有两个目录,分别是 Python2 --> C:\Python27 和 Python365 --> C:\Python365。
要解决此错误:
在cmd 中运行pip install pandas。如果库 Pandas 已安装,您将看到类似以下内容。
pip install pandas
Requirement already satisfied: pandas in c:\python27\lib\site-packages (0.23.4)
Requirement already satisfied: python-dateutil>=2.5.0 in c:\python27\lib\site-packages (from pandas) (2.7.3)
Requirement already satisfied: numpy>=1.9.0 in c:\python27\lib\site-packages (from pandas) (1.14.4)
Requirement already satisfied: pytz>=2011k in c:\python27\lib\site-packages (from pandas) (2018.4)
Requirement already satisfied: six>=1.5 in c:\python27\lib\site-packages (from python-dateutil>=2.5.0->pandas) (1.11.0)
从上面命令的输出可以看出pandas安装在Python2目录下,即C:\python27\lib\site-packages(0.23.4)。
在cmd 中运行python 命令以检查您运行的是哪个Python 版本。
python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
您可以看到我使用的是Python3,而Pandas 安装在Python2 目录中。
要在Python3 中安装 Pandas 和其他库,请转到Python3 directory, i.e., C:\Python365\Scripts 中的脚本文件夹。
打开一个命令窗口并运行pip install pandas。
也可以使用cmd中的Python3目录中pip的完整路径运行install命令,即C:\Python365\Scripts\pip install pandas