因为学习所需,需要用到python3.x的环境,目前Linux系统默认的版本都是python2.x的,还有一些自带的工具需要用到python2.6版本,所以要求的是python3 和 python2 共存,pip2 和** pip3共存,如何安装python3.x的环境?本文是以Python3.5.2**的版本为例。
系统环境:CentOS 6.8-Minimal
1. 安装依赖包:
[root@linuxprobe ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2. 下载Python3.5.2
[root@linuxprobe ~]# cd /usr/local/src
[root@linuxprobe src]# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
# 若提示错误 请加上这个参数"--no-check-certificate"可以下载
3. 安装步骤
[root@linuxprobe src]# mkdir /usr/local/python3.5
[root@linuxprobe src]# tar -zxvf Python-3.5.2.tgz
[root@linuxprobe src]# cd Python-3.5.2
[root@linuxprobe src]# ./configure --prefix=/usr/local/python3.5
[root@linuxprobe src]# make && make install
[root@linuxprobe src]# ln -s /usr/local/python3.5/bin/python3 /usr/bin/python3
或者添加python命令到环境变量
[root@linuxprobe ~]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/python3.5/bin #添加python命令的路径
[root@linuxprobe ~]# source ~/.bash_profile
4. 安装setuptools
可以通过官方模块库来下载:https://pypi.python.org/pypi
[root@linuxprobe src]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz
[root@linuxprobe src]# tar zxvf setuptools-19.6.tar.gz
[root@linuxprobe src]# cd setuptools-19.6.tar.gz
[root@linuxprobe src]# python3 setup.py build
[root@linuxprobe src]# python3 setup.py install
[root@linuxprobe src]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz
[root@linuxprobe src]# tar zxvf pip-8.0.2.tar.gz
[root@linuxprobe src]# cd pip-8.0.2
[root@linuxprobe src]# python3 setup.py build
[root@linuxprobe src]# python3 setup.py install
[root@linuxprobe src]# ln -s /usr/local/python3.5/bin/pip /usr/bin/pip
[root@linuxprobe src]# pip --version #安装成功
pip 8.0.2 from /usr/local/python3.5/lib/python3.5/site-packages/pip-8.0.2-py3.5.egg (python 3.5)
5. 解决python升级后,YUM不能正常工作的问题:
#!/usr/bin/python
改成
#!/usr/bin/python2.6
这样可以保证python2.x和python3.x版本共存,互不冲突了!