centos7源码安装python3.6.7

下载python3,官网地址:https://www.python.org/downloads/

找到对应的安装包,选择源码安装下载。

centos7源码安装python3.6.7_第1张图片

或者复制链接地址可以在命令行直接下载。

[root@hadoop tools]# wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz

 

安装依赖环境。

[root@hadoop tools]# 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@hadoop tools]# tar -zxvf Python-3.6.7.tgz


……

[root@hadoop tools]# cd Python-3.6.7/

 

指定安装目录,进行编译安装。

[root@hadoop Python-3.6.7]# ./configure --prefix=/usr/local/python3

指定CPU核心数进行编译安装

[root@hadoop Python-3.6.7]# make -j `cat /proc/cpuinfo| grep "processor"| wc -l` && make install

 

进入python3环境进行简单测试。

[root@hadoop Python-3.6.7]# cd /usr/local/python3/bin/
[root@hadoop bin]# ./python3

Python 3.6.7 (default, Jan 21 2019, 10:20:03)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello word")
hello word
>>> print "hello word"
  File "", line 1
    print "hello word"
                     ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("hello word")?
>>> quit()

此处说明python3环境已安装完成,因为python3已将print列为函数了,使用时必须添加圆括号。

 

建立软连接使其在其他目录也可以使用,但不能印象原来python的使用,因为原来的环境需要用到python2环境,比如yum。

[root@hadoop bin]# ln -s /usr/local/python3/bin/python3 /usr/bin/


配置环境变量

[root@hadoop bin]# vim /root/.bashrc

# User specific environment and startup programs

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


export PATH

[root@hadoop bin]# source /root/.bashrc


测试是否成功

[root@hadoop bin]# cd /root/
[root@hadoop ~]# python3
Python 3.6.7 (default, Jan 21 2019, 10:20:03)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()

 

你可能感兴趣的:(python)