CentOS7 安装 python 3.7.4
# 安装环境(最小化安装)
CentOS Linux release 7.0.1406 (Core)
# 下载安装包
https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
# 安装依赖包
yum install gcc zlib* libffi-devel
# 解压
tar -xvf Python-3.7.4.tar.xz
# 编译、安装
cd Python-3.7.4
./configure
make
make install
# 安装成功验证
执行 python3 -V
Python 3.7.4
⚠️注意:编译安装注意是否有报错!
缺失gcc库编译报错:configure: error: no acceptable C compiler found in $PATH
解决办法:
yum install gcc
缺失zlib库安装报错:zipimport.ZipImportError: can't decompress data; zlib not available
解决办法:
yum install zlib* (安装完成后需要重新编译)
缺少libffi-devel安装报错: ModuleNotFoundError: No module named '_ctypes'
解决办法:
yum install libffi-devel
缺失ssl模块:ModuleNotFoundError: No module named '_ssl' 或
Can't connect to HTTPS URL because the SSL module is not available
解决办法:
安装openssl-devel,修改安装配置,并重新编译安装
yum install openssl-devel
编辑安装文件,
vi Python-3.7.4/Modules/Setup
将ssl注释去掉,修改配置如下:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
重新安装
make && make install
更换pip安装源
# 更换安装源
pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple/
Writing to /root/.config/pip/pip.conf
# cat ~/.config/pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple
trusted-host = mirrors.aliyun.com
# 其他国内pip源如下,注意如果pip安装报错:centos Can't connect to HTTPS URL because the SSL module is not available
# 可以更换为http安装源
阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学http://pypi.hustunique.com/