2016-05-12 447 views
0

我有一些運行得很好的代碼,並且在一天當中,我破壞了一些東西,現在我無法安裝任何python模塊。具體來說,我需要numpy,matplotlib和枕頭。我無法安裝其中的任何一個。Python模塊沒有安裝

但奇怪的是,他們似乎都安裝就好了:

$ sudo pip install numpy 
Collecting numpy 
    Downloading numpy-1.11.0-cp27-cp27mu-manylinux1_x86_64.whl (15.3MB) 
    100% |████████████████████████████████| 15.3MB 94kB/s 
Installing collected packages: numpy 
Successfully installed numpy-1.11.0 

或當我嘗試:

$ sudo apt-get install python-numpy 
Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
Suggested packages: 
    python-nose python-numpy-dbg python-numpy-doc 
The following NEW packages will be installed: 
    python-numpy 
0 upgraded, 1 newly installed, 0 to remove and 20 not upgraded. 
Need to get 0 B/1,763 kB of archives. 
After this operation, 9,598 kB of additional disk space will be used. 
Selecting previously unselected package python-numpy. 
(Reading database ... 221259 files and directories currently installed.) 
Preparing to unpack .../python-numpy_1%3a1.11.0-1ubuntu1_amd64.deb ... 
Unpacking python-numpy (1:1.11.0-1ubuntu1) ... 
Processing triggers for man-db (2.7.5-1) ... 
Setting up python-numpy (1:1.11.0-1ubuntu1) ... 

我使用python 2.7,我在Ubuntu 16.04。

$ python 
Python 2.7.5 (default, May 12 2016, 13:11:58) 
[GCC 5.3.1 20160413] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import numpy 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named numpy 
>>> 

它爲我嘗試安裝的任何模塊執行此操作。任何幫助將不勝感激。

+0

'哪個python'和'sudo pip -V'的輸出是什麼? –

+0

pip 8.1.2來自/usr/local/lib/python2.7/dist-packages(python 2.7) –

+0

難道你有多個Python安裝並且只安裝numpy到其中的一個? – roadrunner66

回答

0

這是默認python和默認pip不匹配的結果。爲了確保軟件包安裝到正確的位置,用途:

python -m pip install $PACKAGE

這導致運行分配到所需python,而不是在您的路徑找到的第一個pip