在安装 Python 3.4 的同时为 Python 2.7 安装 numpy?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25900818/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:48:12  来源:igfitidea点击:

Installing numpy for Python 2.7 while also having Python 3.4 installed?

pythonpython-2.7numpypython-3.4

提问by David

I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7.

我有 Python 2.7 和 Python 3.4(并且必须同时拥有,因为对于我正在运行的课程,学生可以选择使用任何一个)。一位学生在他们的项目中使用了 Python 2.7 和 numpy,但是当我尝试安装 numpy 时,它会将其安装到 3.4。我需要将其安装到 2.7。

I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/

我正在使用来自这个站点的 numpy 1.9,我被告知它也是 2.7 特定的:http: //sourceforge.net/projects/numpy/files/NumPy/

However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn't work, obviously.

但是,它仍然会转到 3.4 文件夹。显然,将它复制到 Python 2.7 是行不通的。

How do I do this?

我该怎么做呢?

采纳答案by justengel

I recommend installing with pip.

我建议使用 pip 安装。

pip install numpy

If this doesn't work on windows then download the binary from http://www.lfd.uci.edu/~gohlke/pythonlibs/and convert it to a wheel before installing.

如果这在 Windows 上不起作用,请从http://www.lfd.uci.edu/~gohlke/pythonlibs/下载二进制文件,并在安装前将其转换为轮子。

pip install wheel
wheel convert path/to/binary
pip install numpy_wheel 

Pip is recommended because you can uninstall.

推荐使用pip,因为可以卸载。

To check where you are installing to

检查您要安装到的位置

pip -V

You may have an environmental variable path to the wrong pip.

您可能有一个指向错误 pip 的环境变量路径。

回答by eandersson

Assuming that you are using, or at least you should use pipto install the library. You can specify the python version to be installed by changing the suffix, e.g. pip-2.7 install numpy.

假设您正在使用,或者至少您应该使用pip来安装库。您可以通过更改后缀来指定要安装的 python 版本,例如pip-2.7 install numpy.

pip install numpy
pip-2.7 install numpy
pip-3.4 install numpy

As an alternative, in case that you do not want to use pip is to download and install the library using setup with a similar technique.

作为替代方案,如果您不想使用 pip,可以使用类似技术的 setup 下载并安装库。

python setup.py install
python2.7 setup.py install
python3.4 setup.py install

回答by jakebrinkmann

Your PATHisn't setup correctly.

PATH的设置不正确。

C:> where pip

Should tell you which pip it is trying to use, and it is likely whichever one it found on your PATHfirst...

应该告诉您它正在尝试使用哪个 pip,并且很可能是它在您的PATH第一个中找到的那个...

So, instead, you will want to run it as

因此,相反,您将希望将其运行为

C:> C:\mypython2install\pip.exe install numpy

Or, setup your path correctly. See here

或者,正确设置您的路径。看这里

回答by suze1992

Just one other note on issues like this. I had a similar problem with Python 2.7 libraries not being found, because I had miniconda installed for a Python virtual environment that was hiHymaning calls to python from other programs. After deleting the minconda directory in my home the problem went away and python libraries that were properly installed were found again.

关于此类问题的另一个说明。我在找不到 Python 2.7 库时遇到了类似的问题,因为我为 Python 虚拟环境安装了 miniconda,该环境劫持了其他程序对 Python 的调用。删除我家中的 minconda 目录后,问题消失了,再次找到了正确安装的 python 库。

回答by sangwan9

Note-This answer is particularly for Windows PC which has both Python2 & Pyhton3 installed on it.

注意- 此答案特别适用于安装了 Python2 和 Pyhton3 的 Windows PC。

Both the versions of Python has their different directories somewhat like

两个版本的 Python 都有不同的目录,有点像

"C:\Python27\" ----for python2

"C:\Python35\" ---- for python3

"C:\Python27\" ----对于python2

"C:\Python35\" ---- 对于 python3

*(or it depends on what path you chose while installing Python**)*

*(或者取决于您在安装 Python 时选择的路径**)*

pip GENERALLY exist under the directory "C:\Python**\Scripts"

pip 一般存在于目录“C:\Python**\Scripts”下

there you can find exe files like:

在那里你可以找到 exe 文件,如:

pip.exe/pip2.exe/pip2.7.exe ----for python2

pip3.exe/pip3.5.exe ----for python3

pip.exe/pip2.exe/pip2.7.exe ----对于python2

pip3.exe/pip3.5.exe ----用于python3

to install packages on python2:

在 python2 上安装软件包:

use

Python27\Scripts\pip2.exe install package_name

Python27\Scripts\pip2.exe 安装包名称

(where the 1st argument is the path of exe file, it might differ for your system)

(其中第一个参数是 exe 文件的路径,它可能因您的系统而异)

to install packages on python3:

在 python3 上安装软件包:

use

Python35\Scripts\pip3.exe install package_name

Python35\Scripts\pip3.exe 安装包名称

there is no need to uninstall any version of python to achieve the task.

无需卸载任何版本的python即可完成任务。