注意事项
Linux一般会默认安装python2,最好保留这个版本的python,因为Linux有软件依赖于python2,比如yum。
Python3安装过程
-
下载对应的Python版本
Python下载地址# 在终端中可以直接用wget $ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
-
安装依赖环境
# Debian/Ubuntu中自带了Python3,安装最新版需要安装编译的依赖包 $ aptitude -y install gcc make zlib1g-dev # Red Hat/CentOS $ 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
-
解压安装
# 解压 $ tar -zxvf Python-3.6.5.tgz # 编译安装 $ cd python-3.6.5 $ ./configure --prefix=/usr/local/python3 $ make && make install # 将python3和pip3软链接到系统的PATH路径 $ ln -s /usr/local/python3/bin/python3 /usr/bin/python3 $ ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
-
验证Python和pip是否安装成功
$ python3 -V Python 3.6.5 $ pip3 -V pip 9.0.3 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)