Python入門之安裝numpy和pandas


最近要對一系列數據做同比比較,需要用到numpy和pandas來計算,不過使用python安裝numpy和pandas因為linux環境沒有外網遇到了很多問題就記下來了。

首要條件,python版本必須是2.7以上。

 

linux首先安裝依賴包

yum -y install blas blas-devel lapack-devel lapack
yum -y install seaborn scipy
yum -y install freetype freetype-devel libpng libpng-devel
yum -y install python-pip
yum -y install pytz
yum -y install python-dateutil

  

1、 pip方式安裝

如果有外網一般推薦使用pip安裝,linux下和windows下均可使用pip安裝

python -m pip install --upgrade pip   #升級pip組件

pip install --user numpy scipy matplotlib jupyter pandas sympy nose

 

但很快就會發現這些源安裝超級慢,所以我推薦大家使用豆瓣的源

pip install matplotlib -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install pandas -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install seaborn scipy  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

 

在window系統中,可以打開多個cmd界面,異步進行安裝,如下圖

 

2、如果服務器上沒有外網使用不了pip,則需要使用源碼安裝。

推薦大家在豆瓣pypi下載,速度更快  https://pypi.doubanio.com/simple/?allow_list_dir=1

python numpy安裝包下載地址是 https://pypi.python.org/pypi/numpy/

pandas的安裝包下載地址是 https://pypi.python.org/pypi/pandas

github地址是 https://github.com/pandas-dev

tar -xzf numpy-1.11.2.tar.gz
cd numpy-1.11.2
python setup.py build  # 編譯幾分鍾
python setup.py install  

 

如提示缺少 setuptools ,從https://pypi.python.org/pypi/setuptools下載 setuptools安裝。

安裝pandas會提示 ImportError: Building pandas requires cython則需要安裝Cython或者升級Cython先,下載鏈接 https://pypi.python.org/pypi/Cython/ 

 

windows下pip安裝如下

python -m pip install Cython

 

linux下可使用yum安裝或者pip安裝

yum install -y Cython.x86_64

 

如果需要更新到最新版本的Cython則下載源碼后安裝

cd Cython-0.25.1
python setup.py build
python setup.py install

 

然后是按照pandas

cd pandas-0.19.0
python setup.py build   # 比較久
python setup.py install

 

如果遇到需要安裝 python-dateutil的提示則是該庫版本過低。先下載six最新版本1.9.0(下載地址),然后更新 python-dateutil到新版本2.5.3版本(下載地址)。

最后運行如果出現 /usr/lib64/libstdc++.so.6: ELF file OS ABI invalid的錯誤則將 /usr/lib64/libstdc++.so.6軟鏈指向低版本的 libstdc++.so.6.0.8,不要指向高版本 libstdc++.so.6.0.20。

至此就安裝成功了。

 

 

 

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM