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')