为python 2.7而不是3.4安装numpy

问题描述:

我一直在努力为python 2.7而不是3.4安装numpy,这两个都在我的ubuntu上.我已经尝试过:

I have been literally struggling to install numpy for python 2.7 and not 3.4 both of which are on my ubuntu. I have tried:

sudo pip2安装numpy

sudo pip2 install numpy

但它说

Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages

但是当我转到python shell并键入import numpy时,它会抛出ImportError

but when I go to the python shell, and type import numpy, it throws an ImportError

python --version prints `Python 2.7.5`

即使查看了其他SO问题的各种答案,我也不知道问题出在哪里.是否已安装numpy且由于某种原因我无法使用它或未安装?请帮忙.

I have no idea what the problem is even after looking at various answers to other SO questions. Is numpy installed and I'm not able to use it for some reason or isn't it installed? Please help.

首先,执行pip uninstall numpypip2 uninstall numpy只是清理所有旧文件.

First, do pip uninstall numpy and pip2 uninstall numpy just to clean up any old files.

然后,由于您使用的是Ubuntu,因此您应该只运行

Then, since you are on Ubuntu, you should just run

sudo apt-get install python-numpy

这将为python2安装numpy.如果以后选择要在python3中使用,只需运行

This will install numpy for python2. If you later choose you want it for python3, just run

sudo apt-get install python3-numpy