Linux 安装Python3

2017-12-14 12:46

Linux自带Python2.x版本,Python3的安装方法有多种,本文介绍安装包安装

安装开发依赖

1
yum -y groupinstall development
2
3
yum -y install zlib-devel

下载Python3安装包

1
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
2
3
tar zxvf Python-3.6.3.tgz
4
5
cd Python-3.6.3
6
7
./configure
8
9
make && make install

跑完之后,查看python3安装位置

1
which python3
2
3
显示如下:
4
[root@ ~]# which python3
5
/usr/local/bin/python3

表示安装成功,此时Python2与Python3都安装在系统中

使用不同python版本

此时系统的默认Python版本2.x

1
python
2
ython 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
3
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
4
Type "help", "copyright", "credits" or "license" for more information.
5
>>>

输入exit(),退出python程序

使用python3

1
python3
2
Python 3.6.3 (default, Dec 14 2017, 19:33:57)
3
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
4
Type "help", "copyright", "credits" or "license" for more information.
5
>>>

输入exit(),退出python3程序

使用python3则运行python3命令,使用python2则运行python


标签: Python

License(CC)BY-NC-SA © 2017 — 2020 hadronw | Theme based on fzheng.me