如何在环境中安装库?

How can I install a library in an environment?

我目前正在使用 python 3.6.5。我的作业需要 python 2。所以我在 Pycharm 中创建了一个 python 2.7 的环境。我想安装 numpy 库。但是,无法使用 Pycharm 安装。 Pycharm 提示通过终端安装。我的操作系统是Win10,python 2.7的路径是

C:\Users\yashir\PycharmProjects\CSC411_A1\venv\Scripts\python.exe

我试过了

pip2 install numpy

它returns

'pip2' is not recognized as an internal or external command,
operable program or batch file.

我该如何解决?

在终端中使用pip之前,需要将其添加到环境变量中:

此页面将为您提供指导:link

我尝试了以下方法并且有效。

C:\Users\yashi>cd PycharmProjects\CSC411_A1\venv\Scripts

pip2 install numpy

但是又引发了另一个问题

Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

所以我下载了文件 numpy-1.15.2-cp27-none-win_amd64 并执行

pip2 install numpy-1.15.2-cp27-none-win_amd64

然后就可以了。

假设您使用的是 .whl 文件,请改用以下命令:

python -m pip install numpy

不能 100% 确定这是否适用于 python 2.7