CentOS 7安装Python3.6过程

  CentOS 7系统自带了python2,不过可以不用2版本,直接使用python3运行python脚本就可以,但是千万别去懂系统自带的python2,因为有程序依赖目前的python2环境,比如yum!!!!!动了yum就无法运行了,其他有的程序也可能会受影响。明白了上面的,然后就来安装Python3.6:

安装步骤:

1. 安装依赖环境

  # 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

2.下载Python3
  https://www.python.org/downloads/

1
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

3.安装python3

  包安装在/usr/local/Python3(具体安装位置看个人喜好)
  创建目录:

1
# mkdir -p /usr/local/Python3

  解压下载好的Python-3.6.5.tgz包(具体包名因你下载的Python具体版本,我下载的是Python3.6.5这里就以Python-3.6.5.tgz为例)

1
# tar -zxvf Python-3.6.5.tgz

4.进入解压后的目录,编译安装。(如果编译安装过程有报错提示看我的另一个随笔写的解决办法http://www.cnblogs.com/shwee/p/9013851.html)

1
2
# cd Python-3.6.5
# ./configure --prefix=/usr/local/Python3

  然后:make

1
# make

  接着:make install

1
make install    或者 make && make install

5.安装好了,建立python3的软链

1
# ln -s /usr/local/Python3/bin/python3 /usr/bin/python3

6.并将/usr/local/Python3/bin加入PATH

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 . 1
# pip3 -V
pip  9.0 . 1  from  / usr / local / python3 / lib / python3. 6 / site - packages (python  3.6 )

7.pip3如果查看不了,再创建一下pip3的软链接

1
# ln -s /usr/local/Python3/bin/pip3 /usr/bin/pip3

猜你喜欢

转载自www.cnblogs.com/shwee/p/9015059.html