前言
最近折腾SS,需要使用pip3安装,安装pip3前又需要安装python3,python3又需要一堆乱七八糟的问题,由于是使用源码安装,遇到不少问题,在此记录
安装python遇到的问题
一下问题都是在编译或者使用pyhon的时候遇到的,不一而足,在此罗列几个印象深刻的
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
Can’t connect to HTTPS URL because the SSL module is not available
还有python安装完后,使用pip3 install 的时候遇到下面问题
ModuleNotFoundError: No module named ‘_ctypes’
安装python前装依赖
yum install libffi libffi-devel tcl tk tcl-devel tk-devel sqlite-devel bzip2-devel ncurses-devel xz-devel libuuid-devel
上面yum 装的依赖没有openssl,需要手动编译,原因是yum装的版本不符合python3.9的要求, OpenSSL 1.0.2 or 1.1
安装openssl
根据python要求来能满足就行,用1.1.1版本举例
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar zxvf openssl-1.1.1g.tar.gz
chmod -R 755 ./openssl-1.1.1g
cd openssl-1.1.1g
chmod -R 755 ./openssl-1.1.1g
./config --prefix=/usr/local/ssl &&make && make install
替换系统老版本的openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
编译python3
完成上面准备后,进行python3编译
wget http://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar zxvf Python-3.3.0.tgz
cd Python-3.3.0
chmod -R 755 ./
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/ssl/
configure完成后,检查输出,确认下面的3项必须是yes,否则SSL无法编译,后续也无法使用,之前的流程创建bin,lib,include就是为了在这里使用,configure会检查里面的东西是否符合要求
checking for openssl/ssl.h in /usr/local/ssl/… yes
checking whether compiling and linking against OpenSSL works… yes
checking for X509_VERIFY_PARAM_set1_host in libssl… yes
检查通过后
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
python3和pip3就安装完成了