【Linux】CentOS7安装Python3.8

1 下载Gzipped source tarball

wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz

2 解压

tar -xzvf Gzipped source tarball

3 安装所需的其他包

yum install -y gcc

4 编译

进入到Python-3.8.12文件下
编译

./configure --prefix=/usr/local/python3.8/Python-3.8.13
make

make失败:

The necessary bits to build these optional modules were not found:
_bz2                  _curses               _curses_panel      
_dbm                  _gdbm                 _hashlib           
_lzma                 _sqlite3              _ssl               
_tkinter              _uuid                 readline           
zlib                                                           
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, https://github.com/libressl-portable/portable/issues/381

安装所需的包

yum install ncurses-devel
yum install libuuid-devel
yum install -y zlib zlib-devel
yum install sqlite-devel
yum install readline-devel
yum install tkinter
yum -y install tcl-devel tk-devel
yum install lzma
yum install gdbm-devel
yum install xz-devel
yum install libffi-devel

yum -y install ncurses-devel libuuid-devel zlib zlib-devel sqlite-devel readline-devel tkinter tcl-devel tk-devel lzma gdbm-devel xz-devel libffi-devel

5 解决ssl问题

wget --no-check-certificate https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.0.2.tar.gz

mkdir /usr/local/libressl

./configure --prefix=/usr/local/libressl

make & make install

# 创建软连接代替openssl

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl /usr/include/openssl.bak

ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl
ln -s /usr/local/libressl/include/openssl /usr/include/openssl
echo /usr/local/libressl/lib >> /etc/ld.so.conf.d/libressl-3.0.2.conf
ldconfig -v
# 验证是否安装完成
openssl version

6 重新编译

# 编译前需要设置环境变量
export LDFLAGS="-L/usr/local/libressl/lib"
export CPPFLAGS="-I/usr/local/libressl/include"
export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

./configure --prefix=/usr/local/python3.8/Python-3.8.13
make
make install

7 检查编译是否成功

cd /usr/local/python3.8/Python-3.8.13
cd bin
./python3.8

8 添加环境变量

vi /etc/profile

添加内容

export PYTHON_HOME=/usr/local/python3.8/Python-3.8.13
export PATH=${PYTHON_HOME}/bin:$PATH

环境变量生效

source /etc/profile
posted @ 2022-07-17 16:03  默默雷  阅读(710)  评论(0编辑  收藏  举报