Centos 6.5 安装 python3.6.2、pip9.0.1、ipython6.1

说明:由于Cenots 6.5 默认是安装的 python 2.6.6  要想同一台主机使用多个python版本,不能影响原来的版本,因为系统很多还依赖于python,比如 yum    python3.x 版本很多方面更规范标准,可以安装 python 3.5+ 版本

系统环境:

[root@localhost ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@localhost ~]# uname -a
Linux TST-NG-01 2.6.32-431.11.31.el6.ucloud.x86_64 #1 SMP Tue Mar 7 20:19:50 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

一、安装python 3.6.2

 1.1 备份并更换阿里源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo   # 阿里镜像源

1.2 安装 python3.6 需要的依赖包

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel

1.3 python官网获取下载地址(官网:https://www.python.org)

python 3.6.2版本源码tar.gz格式地址:https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz

也可以到搜狐镜像里面去下载源码:   http://mirrors.sohu.com/python/3.6.2/

1.4 登录到要安装python的linux主机,下载 --> 解压 --> 编译 --> 安装

mkdir /data/tools
cd /data/tools
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
tar xf Python-3.6.2.tgz
cd Python-3.6.2
./configure --prefix=/usr/local   # 可以自定义指定python的安装目录,如果指定的安装目录不在 PATH 环境变量里面,需要把安装的目录加入到环境变量中去

如果这步出现如下提示,可以加上这个参数再重新执行一遍   ./configure --prefix=/usr/local --enable-optimizations  也可以忽略这个提示,不影响后面的安装
If you want a release build with all stable optimizations active (PGO, etc), please run .
/configure --enable-optimizations make -j 2 && make install # 由于编译的过程时间比较长,可以启用多核心编译会快点 (命令行输入 top 命令 然后按 1 可以获取主机有几个核) ln -s /usr/local/bin/python3 /usr/bin/python3 # 创建软连接

1.5 检查python3.6.2 是否正确安装

[root@localhost ~]# python3 --version
Python 3.6.2
[root@localhost ~]# python3
Python 3.6.2 (default, Aug 28 2017, 15:41:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

二、安装 pip 包管理工具 pip

官网下载地址:https://pypi.python.org/pypi/pip

cd /data/tools
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz
tar xf pip-9.0.1.tar.gz
cd pip-9.0.1
python3 setup.py install

安装 pip 成功最后面的提示如下

Installed /usr/local/lib/python3.6/site-packages/pip-9.0.1-py3.6.egg
Processing dependencies for pip==9.0.1
Finished processing dependencies for pip==9.0.1

三、安装 ipython

pip install ipython

1.0  进入ipython交互式界面 & 查看ipython版本

[root@localhost ~]# ipython
Python 3.6.2 (default, Aug 28 2017, 15:41:06) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

[root@localhost ~]# ipython --version
6.1.0

1.1  测试

In [2]: print('hello,world!')
hello,world!

In [3]: print(' 安装完成 '.center(30,'*'))
************ 安装完成 ************
***** 不要假装努力,结果不会陪你演戏! *****
原文地址:https://www.cnblogs.com/chenjinxi/p/7444288.html