CentOS 7系统自带了python2,不过能够不用2版本,直接使用python3运行python脚本就能够,可是千万别去动系统自带的python2,由于有程序依赖目前的python2环境,好比yum,动了yum就没法运行了,其余有的程序也可能会受影响。明白了上面的,而后就来安装Python3.6:html
安装步骤: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-develsql
https://www.python.org/downloads/vim
1
|
# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
|
包安装在/usr/local/Python3(具体安装位置看我的喜爱)
建立目录:bash
1
|
# mkdir -p /usr/local/Python3
|
解压下载好的Python-3.6.5.tgz包(具体包名因你下载的Python具体版本,我下载的是Python3.6.5这里就以Python-3.6.5.tgz为例)spa
1
|
# tar -zxvf Python-3.6.5.tgz
|
若是编译安装过程有报错提示看个人另外一个随笔写的解决办法http://www.cnblogs.com/shwee/p/9013851.html3d
1
2
|
# cd Python-3.6.5
# ./configure --prefix=/usr/local/Python3
|
而后:makecode
1
|
# make
|
接着:make installsqlite
1
|
# make install
|
或者两步一块儿:make && make installhtm
1
|
# ln -s /usr/local/Python3/bin/python3 /usr/bin/python3
|
1
2
3
4
5
6
7
8
9
|
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if
[
-
f ~
/
.bashrc ]; then
. ~
/
.bashrc
fi
# User specific environment and startup programs
PATH
=
$PATH:$HOME
/
bin
:
/
usr
/
local
/P
ython3
/
bin
export PATH
|
按ESC,输入:wq,按回车保存退出编辑。
修改完记得执行行下面的命令,让上一步的修改生效:
1
|
# source ~/.bash_profile
|
检查Python3及pip3是否正常可用:
1
2
3
4
|
# python3 -V
Python
3.6
.5
# pip3 -V
pip
9.0
.3
from
/
usr
/
local
/P
ython3
/
lib
/
python3.
6
/
site
-
packages (python
3.6
)
|