微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS 6.10 下源码安装Python 3.7.2

环境:

CentOS release 6.10 (Final)

2.6.32-754.9.1.el6.x86_64

Python源码下载 : https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz

安装前准备

# 解决 import bz2 报错
yum install  bzip2-devel

# 解决 import curses 报错
yum install  ncurses-devel

# 解决 import sqlite3 报错
yum install sqlite-devel

# 解决 _dbm _gdbm 缺失提醒
yum install gdbm-devel

# 解决 _lzma 缺失提醒
yum install xz-devel

# 解决 _tkinter 缺失提醒
yum install tk-devel

# 解决 readline 缺失提醒及方向键行为非预期的问题
yum install readline-devel

yum -y install wget gcc gcc-c++ make zlib  zlib-devel readline-devel  bzip2-devel ncurses-devel sqlite-devel pyliblzma libuuid-devel
yum -y install gdbm-devel xz-devel tk-devel openssl-devel

#源码安装openssl,解决python3.7需要的openssl版本最低为1.0.2 解决:libffi libffi-develtkinter tcl-devel db4-devel libpcap-devel xz-devel gdbm-devel
yum -y groupinstall "Development tools"
tcl-develImportError: No module named _ssl
cd /opt
wget
https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar xf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a/
./config --prefix=/opt/openssl shared zlib
make && make install
vi /etc/ld.so.conf

分享图片

  ldconfig

 

安装

cd /opt

wget https://www.python.org/ftp/python/3.7.2/python-3.7.2.tgz

tar xf python-3.7.2.tgz

cd python-3.7.2

sed -i s/^#readline/readline/ Modules/Setup.dist
sed -ri s/^#(_ssl)/\1/p Modules/Setup.dist 
sed -ri s/^#([\t]-DUSE)/\1/p Modules/Setup.dist 
sed -ri s/^#([\t]-L\$(SSL))/\1/p Modules/Setup.dist

./configure --prefix=/opt/python3 --with-openssl=/opt/openssl --enable-shared --enable-optimizations

make

make install

 

ln -s /opt/python3/bin/python3 /bin/

ln -s /opt/python3/bin/pip3 /bin/

 

参考:

https://blog.51cto.com/13575683/2114585

https://www.jianshu.com/p/9b8ffb22687a

https://www.jianshu.com/p/3ec24f563b81

等等。。。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。