centos6.9下安裝python3.7


說明

以下所有操作都基於centos6.9

python3.7依賴openssl1.0.2,首先更新系統自帶的openssl

建議

升級系統到centos7(系統openssl已升級到1.0.2)

升級openssl

cd /ddhome/tools
wget -c https://www.openssl.org/source/openssl-1.0.2p.tar.gz
tar -xf /ddhome/src  # 這里不能用-xzvf,否則python3.7裝不了ssl模塊

# 配置ssl
cd /ddhome/src
./config shared zlib    # shared zlib也不可缺少
make && make install
mv /usr/bin/openssl /usr/bin/openssl-1.0.1e
mv /usr/include/openssl /usr/include/openssl-1.0.1e
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl

# 添加庫文件路徑
#ln -s /usr/local/ssl/lib/libssl.so /usr/local/lib64/libssl.so
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
#echo "/usr/local/lib64" >> /etc/ld.so.conf

# 替換老版本libssl.so軟鏈接
[root@ddcvb openssl-1.0.2]# ll /usr/lib64/libssl.so 
lrwxrwxrwx. 1 root root 16 Aug 25 15:22 /usr/lib64/libssl.so -> libssl.so.1.0.1e
[root@ddcvb openssl-1.0.2]# ll /usr/lib64/libssl.so.10
lrwxrwxrwx. 1 root root 16 Aug 23 04:36 /usr/lib64/libssl.so.10 -> libssl.so.1.0.1e
rm -rf /usr/lib64/libssl.so
ln -s /usr/local/ssl/lib/libssl.so  /usr/lib64/libssl.so

# 刷新庫文件
ldconfig -v

# 注意
/usr/lib64/libssl.so.10 不要刪, python2.7用的就是它

# 查看版本
openssl version -a

安裝依賴包

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

# 3.7必須安裝
yum -y install libffi-devel

下載python3.7並配置

cd /ddhome/tools
wget -c https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -xzvf Python-3.7.0 -C /ddhome/src

cd /ddhome/src
./configure

開啟ssl

開啟ssl模塊,要不然pip安裝https請求的所有模塊都會失敗,而且必須在make之前完成
先配置python,即先運行 ./configure, 會出現./Module/Setup文件

vim Module/Setup, 修改如下

# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

安裝twisted

wget -c https://files.pythonhosted.org/packages/90/50/4c315ce5d119f67189d1819629cae7908ca0b0a6c572980df5cc6942bc22/Twisted-18.7.0.tar.bz2
tar jxvf Twisted-18.7.0.tar.bz2

python3 setup.py install

安裝python3.7

cd /ddhome/src
make && make install

安裝爬蟲依賴包

pip3 install request selenium scrapy

安裝圖形編程接口

python的圖形編程接口, 使用matplotlib做圖時需要

# centos
yum install -y tkinter tk-devel

# ubuntu
sudo apt-get install python-tk

安裝科學計算相關包

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

安裝pyecharts

pip3 install pyecharts

# Geo Data extensions 
pip3 install echarts-cities-pypkg

# Map extensions
pip3 install echarts-countries-pypkg
pip3 install echarts-china-provinces-pypkg
pip3 install echarts-china-cities-pypkg
pip3 install echarts-china-counties-pypkg
pip3 install echarts-china-misc-pypkg
pip3 install echarts-united-kingdom-pypkg

matplotlib圖形化展示

_tkinter.TclError: no display name and no $DISPLAY environment variable
解決:首行加入下面兩句話:
import matplotlib

# Force matplotlib to not use any Xwindows backend. 
matplotlib.use('Agg')


免責聲明!

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



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