【转载】Centos 安装 Python3 环境

原文
CentOS7 默认自带 Python2.7,可安装 Python3 与 Python2 共存。

[root@Python ~]# python -V
Python 2.7.5

1.安装编译相关工具

1. [root@Python ~]# cat /etc/redhat-release
  
2. CentOS Linux release 7.6.1810 (Core)
[root@Python ~]# yum -y groupinstall "Development tools"
[root@Python ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
[root@Python ~]# yum install wget libffi-devel -y

2.下载安装包并解压

[root@Python ~]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
[root@Python ~]# tar  -xvJf  Python-3.7.0.tar.xz

3.编译安装

[root@Python ~]# mkdir /usr/local/python3
[root@Python ~]# cd Python-3.7.0
[root@Python ~]# ./configure --prefix=/usr/local/python3
...
[root@Python ~]# make && make install
...

4.设置环境变量

这一步和原博客不同,应该是对 /etc/profile 进行编辑

[root@iZkrh04kg2zswmZ /]# vim /etc/profile

插入内容

export PATH=/usr/local/python3/bin:$PATH:

保存退出,使其生效

[root@syztoo ~]# source /etc/profile

5.验证安装情况

[root@docker Python-3.7.0]# python3 -V
Python 3.7.0
[root@docker Python-3.7.0]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
# Linux 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×