centos7中安装python3.7遇到的问题

安装python3.7的步骤

wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz

yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

tar xvf Python-3.7.3.tar.xz

cd Python-3.7.3/

./configure --prefix=/opt/python3.7 #指定安装目录

在安装过程中遇到两处错误

1"zipimport.ZipImportError: can't decompress data; zlib not available"错误提示,

缺少zlib依赖导致

解决方法:yum install zlib zlib-devel -y

2 ModuleNotFoundError: No module named '_ctypes' 错误提示

缺少libffi依赖导致:

解决方法:yum install libffi-devel -y

3: pip不能使用的问题

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443):

没有安装openssl软件包导致

解决方法:yum -y install openssl-devel openssl

问题解决后添加环境变量并加载配置

在/etc/profile 中添加

PATH=/opt/python3.7/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

加载配置文件

source /etc/profile

4.在安装python虚拟环境软件包时报以下错误

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-2oveqest/virtualenvwrapper/

这个是python版本问题导致

所以

python3 -m pip install --upgrade --force pip #升级一下pip使之兼容python2就解决了

5在安装python3是出现

configure:3885: error: no acceptable C compiler found in $PATH

解决方式:yum -y install gcc