CentOS7 Python多版本安装

2018-04-04  本文已影响0人  A04

  CentOS7上默认已经有python2.7,但平时经常使用到python3.4,所以需要再安装一个3.4版本python,安装过程参考链接【https://blog.csdn.net/anderslu/article/details/71336210】,内容如下

安装相关包

# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-de

使用make指令安装python3.5

(1)# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz

(2)# tar xf Python-3.5.3.tar.xz -C /usr/local/src/ (yum -y install xz  #若失败,重建yum缓存.yum clean all ,yum makecache)

(3)# cd /usr/local/src/Python-3.5.3

(4)#./configure --prefix=/usr/local/python3

(5)#make && make install

//从 Python 3.4 开始就已经自带了 pip 和 easy_install(setuptools 包带的命令) 包管理命令,你可以在 /usr/local/python3/bin/ 目录下看到,查看一下已经安装的扩展包:

(6)#/usr/local/python3/bin/pip3 list
pip (8.1.1)
setuptools (20.10.1)

You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

 // 更新pip
(7)#/usr/local/python3/bin/pip3 install --upgrade pip
(8)# /usr/local/python3/bin/pip3 list

pip (8.1.2)
setuptools (20.10.1)

//查看是否安装成功

(9)执行ln -s /usr/local/python3/bin/python3 /usr/bin/python3命令创建软连接。

执行python -V查看Python是否安装成功。

# python -V

Python 3.5.3

//安装完成。

  安装过程基本顺利,只不过上面是用3.5,我安装的是3.4,python3.4上面的安装目录是python3,我使用了python34,最后创建连接的时候方法如下:

进入python3.4所在的目录
[root@localhost bin]# pwd
/usr/local/python34/bin
[root@localhost bin]# ./python3.4
Python 3.4.4 (default, Apr  4 2018, 15:09:11) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

创建连接
[root@localhost bin]# ln -i /usr/local/python34/bin/python3.4 /usr/bin/python34
[root@localhost bin]# python34
Python 3.4.4 (default, Apr  4 2018, 15:09:11) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
[root@localhost bin]#

在centos上任意路径,使用python34即可进入python3.4
[root@localhost bin]# cd /
[root@localhost /]# python34
Python 3.4.4 (default, Apr  4 2018, 15:09:11) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

使用python即可进入python2.7
[root@localhost /]# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost /]# 

  通过上述配置可以便捷地选择python版本。

  在pycharm中选择python3.4,参考下图步骤,步骤7选定python3.4所在目录

上一篇下一篇

猜你喜欢

热点阅读