Python3.7.2安装
初始依赖包
yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc libffi-devel libcurl-devel下载源码包
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz解压安装
tar -zxf Python-3.7.2.tgz
cd Python-3.7.2
./configure --prefix=/usr/local/python3
make && make install安装完之后添加软链接,方便使用命令
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3错误处理
安装python3.11.1后使用pip3安装模块会报如下错误
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.解决方案; 手动安装较新版本的openssl
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate
tar -zxvf openssl-1.1.1.tar.gz
cd openssl-1.1.1
./config --prefix=/usr/local/openssl shared zlib
make
make install
rm -rf /usr/bin/openssl
rm -rf /usr/lib64/libssl.so.1.1
rm -rf /usr/lib64/libcrypto.so.1.1
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/
openssl version重新编译安装Python,配置时指定openssl新版本的位置 重新配置需要加上--enable-optimizations参数
tar -zxf Python-3.11.1.tgz
cd Python-3.11.1
./configure --prefix=/usr/local/python3 --enable-optimizations --with-openssl=/usr/local/openssl
make && make install
# 创建软件链接,如果之前有创建过,需要先删除。
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3安装scrapy
pip3 install scrapy
pip3 install --proxy=http://127.0.0.1:1080 # 如果下载太慢可以用代理加速,指定代理服务器信息即可遇到如下错误
Could not find a version that satisfies the requirement Twisted>=13.1.0 (from scrapy) (from versions: ) No matching distribution found for Twisted>=13.1.0 (from scrapy)
是因为没安装Twisted或版本低于13.1.0 到 https://pypi.org/ 搜索、下载源码包来安装
我这里下载的是Twisted-18.9.0.tar.bz2
tar -jxf Twisted-18.9.0.tar.bz2
cd Twisted-18.9.0
python3 setup.py install最后更新于