Centos下的Python安装及解决No module named _ ssl报错
1 下载依赖包(已有依赖可跳过)
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel
yum install wget
2 下载Python和OpenSSL
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tgz
当然官网下载速度可能比较感人,也可以使用国内镜像源来下载:
wget https://repo.huaweicloud.com/python/3.11.0/Python-3.11.0.tgz
下载OpenSSL,需要在1.1.1版本以上。
wget https://codeload.github.com/openssl/openssl/tar.gz/refs/tags/OpenSSL_1_1_1q
3 安装OpenSSL
tar -zxvf openssl-OpenSSL_1_1_1q.tar.gz
cd openssl-OpenSSL_1_1_1q/
./config --prefix=/usr/local/openssl
make && make test && make install
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/
4 安装python
tar -zxvf Python-3.11.0.tgz
cd Python-3.11.0/
vim Modules/Setup
将 To statically link OpenSS 下面的五行注释取消注释
./configure -C --with-openssl=/usr/local/openssl --with-openssl-rpath=auto --prefix=/usr/local/python3
make -j8
make altinstall
ln -s /usr/local/python3/bin/python3.10 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip3
python3 -V