Installation des Centos7-Quellcodes in Python3

Installation des Centos7-Quellcodes in Python3

1. Bereiten Sie OpenSSL vor

# 查看openssl版本,过低的需要重新安装
[root@lemon Python-3.7.3]# openssl version
OpenSSL 1.1.1g  21 Apr 2020

# 安装高版本的openssl
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g/
./config --prefix=/usr/local/openssl
make
make install

# 备份和替换
mv /usr/bin/openssl /usr/bin/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig 

Zweitens installieren Sie Python3

# 安装libffi,libffi-devel
yum install -y libffi libffi-devel

# 下载python安装包
wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz
tar -xvf Python-3.10.12.tgz
cd Python-3.10.12

# 预编译和编译
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --enable-shared
make && make install

--prefix是安装目录
--enable-shared是编译后,会生成python的库。在编译完后,手动将libpython3.10.so.1.0拷贝到/lib/lib64下
--with-openssl=/usr/local/openssl/ 这个是让编译生成的python支持ssl。务必带上这个,不然后面使用编译后的pip去下载包的时候,如果是公网,比如清华的,那就必须得支持ssl。这里的目录是make install时openssl的安装目录

# 创建快捷方式
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip

3. Ändern Sie das Yum-Skript

Das Yum von Centos7 verwendet standardmäßig Python2. Da Centos7 nun in Python3 geändert wurde, müssen Sie Yum angeben, um Python2 zu verwenden

vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down

将第一行的/usr/bin/python修改为/usr/bin/python2

Guess you like

Origin blog.csdn.net/weixin_45455015/article/details/131292001