Linux自带python版本一般是2.7,如果想安装python3,且要指定版本要怎么做呢,下面以CentOS7下安装python3.7举例。
1)下载
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
tar -zxvf Python-3.7.9.tgz
cd Python-3.7.9
2)修改配置文件支持ssl
需要修改安装配置,否则安装后使用pip时会因为不支持ssl导致安装不了包
vim Modules/Setup.dist
# 搜索SSL,将这几行的注释打开
_socket socketmodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
3)编译
./configure
这里可能会缺少一些依赖库,根据提示安装上去即可,比如gcc、openssl
yum install gcc-c++
yum install openssl-devel
4)安装
make
make install
完成!