python3.7安装教程linux_linux系统安装Python 3.7.x

1. 基础环境。

[root@monitor ~]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

2. 升级openssl。CentOS 7.6默认自带的openssl是1.0.2,需要升级到1.1.1,否则使用pip安装模块是会报错“pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available”。(如果是先装的Python,后升级的openssl,则升级完后需要重新编译Python)

[root@monitor ~]# openssl version

OpenSSL 1.0.2k-fips 26 Jan 2017

# 安装依赖。如果是CentOS 6.x的系统需要安装xz,否则下面解压Python压缩包会报错。

[root@monitor ~]# yum -y install gcc xz

# 下载新版本的openssl

[root@monitor ~]# cd /usr/local/src

[root@monitor src]# wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz

[root@monitor src]# tar xf openssl-1.1.1c.tar.gz

[root@monitor src]# cd openssl-1.1.1c/

[root@monitor openssl-1.1.1c]# ./config --prefix=/usr/local/openssl

[root@monitor openssl-1.1.1c]# make

[root@monitor openssl-1.1.1c]# make install

# 备份原来的openssl,并为新版本的openssl创建软链接。

[root@monitor openssl-1.1.1c]# mv /usr/bin/openssl{,.bak}

[root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/include/openssl /usr/include/openssl

[root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so

[root@monitor openssl-1.1.1c]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

# 写入openssl库文件的搜索路径,并使之生效。

[root@monitor openssl-1.1.1c]# echo "/usr/local/openssl/lib" >>/etc/ld.so.conf

[root@monitor openssl-1.1.1c]# ldconfig -v

[root@monitor openssl-1.1.1c]# openssl version

OpenSSL 1.1.1c 28 May 2019

3. 下载Python 3.7.x的tar包,并解压。

[root@monitor openssl-1.1.1c]# cd /usr/local/src/

[root@monitor src]# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz

[root@monitor src]# tar xf Python-3.7.2.tar.xz

[root@monitor src]# cd Python-3.7.2/

4. 编译安装。

# 安装依赖包。

[root@monitor Python-3.7.2]# yum -y install zlib-devel libffi-devel

[root@monitor Python-3.7.2]# ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl

[root@monitor Python-3.7.2]# make && make install

Successfully installed pip-18.1 setuptools-40.6.2

5. 配置环境变量。

[root@monitor python3]# cd /usr/local/python3/bin/

[root@monitor bin]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

[root@monitor bin]# echo 'export PATH=/usr/local/python3/bin/:$PATH' >>/etc/profile

[root@monitor bin]# . /etc/profile

[root@monitor bin]# python3 -V

Python 3.7.2

6. 测试pip安装requests模块。

[root@monitor bin]# pip3 install requests

Successfully installed certifi-2019.6.16 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.3

写作不易,转载请注明出处,谢谢~~

来源:oschina

链接:https://my.oschina.net/u/4341084/blog/3403028

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值