linux下安裝numpy

CYH_job發表於2017-04-23

一,安裝步驟

NumPy函式庫是Python開發環境下的一個獨立的模組。

1.下載原始碼包:
wget http://jaist.dl.sourceforge.net/project/numpy/NumPy/1.9.0/numpy-1.9.0.zip

2.解壓
unzip numpy-1.9.0.zip

3.進入解壓目錄
cd numpy-1.9.0

4.執行解壓目錄裡的setup.py 檔案(一定要在root環境下安裝!!!!)
python setup.py install

二,安裝錯誤解決:

在安裝完後,直接執行python,然後輸入from numpy import*,出現了

"ImportError: Error importing numpy: you should not try to import numpy > from its source directory; please exit the numpy source tree, and > relaunch your python intepreter from there." 
的錯誤,通過搜資料,發現是因為沒有進對正確的路徑,在執行此命令時,需要進入的路徑是numpy下的tests資料夾,也就是cd numpy/tests,然後再來進行測試是否安裝成功的命令。

[yqtao@localhost ~]$ python
Python 2.7.5 (default, Sep 15 2016, 22:37:39) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *            //匯入函式庫
>>> eye(4)                         //生成單位矩陣
array([[ 1.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.],
       [ 0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  1.]])

相關文章