Centos7下部署两套python版本并存

 

需求说明:
centos7.2系统的开发机器上已经自带了python2.7版本,但是开发的项目中用的是python3.5版本,为了保证Centos系统的正常运行,以及节省机器资源(不想因此再申请另外一台开发机器部署python3.5),所以需要安装python3.5与python2.7共存的开发环境。具体操作记录如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
1)安装相关包
[root@qd-vpc-rec-dev01 ~]# yum -y install epel-release
[root@qd-vpc-rec-dev01 ~]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
 
2) 编译安装python3.5
[root@qd-vpc-rec-dev01 ~]# yum -y install xz
[root@qd-vpc-rec-dev01 ~]# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
[root@qd-vpc-rec-dev01 ~]# tar xf Python-3.5.3.tar.xz -C /usr/local/src/
[root@qd-vpc-rec-dev01 ~]# cd /usr/local/src/Python-3.5.3
[root@qd-vpc-rec-dev01 Python-3.5.3]# ./configure --prefix=/usr/local/python3
[root@qd-vpc-rec-dev01 Python-3.5.3]# make && make install
 
从 Python 3.4 开始就已经自带了pip和easy_install(setuptools 包带的命令) 包管理命令,你可以在 /usr/local/python3/bin/ 目录下看到,查看一下已经安装的扩展包:
[root@qd-vpc-rec-dev01 Python-3.5.3]# ll /usr/local/python3/bin/
total 24080
lrwxrwxrwx 1 root root        8 Sep 27 19:40 2to3 -> 2to3-3.5
-rwxr-xr-x 1 root root      109 Sep 27 19:40 2to3-3.5
-rwxr-xr-x 1 root root      250 Sep 27 19:40 easy_install-3.5
lrwxrwxrwx 1 root root        7 Sep 27 19:40 idle3 -> idle3.5
-rwxr-xr-x 1 root root      107 Sep 27 19:40 idle3.5
-rwxr-xr-x 1 root root      222 Sep 27 19:40 pip3
-rwxr-xr-x 1 root root      222 Sep 27 19:40 pip3.5
lrwxrwxrwx 1 root root        8 Sep 27 19:40 pydoc3 -> pydoc3.5
-rwxr-xr-x 1 root root       92 Sep 27 19:40 pydoc3.5
lrwxrwxrwx 1 root root        9 Sep 27 19:40 python3 -> python3.5
-rwxr-xr-x 2 root root 12309757 Sep 27 19:39 python3.5
lrwxrwxrwx 1 root root       17 Sep 27 19:40 python3.5-config -> python3.5m-config
-rwxr-xr-x 2 root root 12309757 Sep 27 19:39 python3.5m
-rwxr-xr-x 1 root root     3088 Sep 27 19:40 python3.5m-config
lrwxrwxrwx 1 root root       16 Sep 27 19:40 python3-config -> python3.5-config
lrwxrwxrwx 1 root root       10 Sep 27 19:40 pyvenv -> pyvenv-3.5
-rwxr-xr-x 1 root root      244 Sep 27 19:40 pyvenv-3.5
[root@qd-vpc-rec-dev01 Python-3.5.3]# /usr/local/python3/bin/pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
setuptools (28.8.0)
 
-----------------------------------------------------------------------------------------------------------------------------
如果要更新pip,操作如下:
[root@qd-vpc-rec-dev01 Python-3.5.3]# /usr/local/python3/bin/pip3 install --upgrade pip
[root@qd-vpc-rec-dev01 Python-3.5.3]# /usr/local/python3/bin/pip3 list
-----------------------------------------------------------------------------------------------------------------------------
 
3)创建软连接
[root@qd-vpc-rec-dev01 Python-3.5.3]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
 
4) 执行python -V查看Python是否安装成功。
[root@qd-vpc-rec-dev01 Python-3.5.3]# python3 -V
Python 3.5.3
 
自带的版本为:
[root@qd-vpc-rec-dev01 Python-3.5.3]# python -V         
Python 2.7.5
 
[root@qd-vpc-rec-dev01 Python-3.5.3]# which python
/usr/bin/python
[root@qd-vpc-rec-dev01 Python-3.5.3]# which python3
/usr/bin/python3
[root@qd-vpc-rec-dev01 Python-3.5.3]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help""copyright""credits" or "license" for more information.
>>>
[root@qd-vpc-rec-dev01 Python-3.5.3]# python3
Python 3.5.3 (default, Sep 27 2017, 19:38:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help""copyright""credits" or "license" for more information.
>>>
 
也就是说,python指令表示的是2.7.5版本,python3指令表示的3.5.3版本。
开发项目里具体使用那个版本的python,就使用对应的全路径的python指令。
 

Centos7下部署两套python版本并存的更多相关文章

  1. Centos7下部署两套python版本并存环境的操作记录

    需求说明:centos7.2系统的开发机器上已经自带了python2.7版本,但是开发的项目中用的是python3.5版本,为了保证Centos系统的正常运行,以及节省机器资源(不想因此再申请另外一台 ...

  2. CentOS7下部署2套Python版本共存

    参考地址:https://www.cnblogs.com/xuaijun/p/7985245.html 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make in ...

  3. 在Window平台下安装xgboost的Python版本

    原文:http://blog.csdn.net/pengyulong/article/details/50515916 原文修改了两个地方才安装成功,第3步可以不用,第2步重新生成所有的就行了. 第4 ...

  4. Mac OS下使用pyenv管理Python版本

    问题的由来 在开发过程中,可能会遇到多个版本同时部署的情况. Mac OS自带的Python版本是2.x,自己开发需要Python3.x 系统自带的是2.6.x,开发环境是2.7.x 由于Mac机器系 ...

  5. 在tomcat下部署两个或多个项目时 log4j和web.xml配置webAppRootKey 的问题(转)

    在tomcat下部署两个或多个项目时 web.xml文件中最好定义webAppRootKey参数,如果不定义,将会缺省为"webapp.root",如下: <!-- 应用路径 ...

  6. CentOS7下部署rsync服务

    说明: 在CentOS7下部署rsync服务和在CentOS6上部署基本上是一样的,只是CentOS7自带了rsyncd启动脚本,由systemd管理而已. rsync服务端配置 [root@SERV ...

  7. tomcat下部署两个工程时,只有一个可以访问,另一个出现404错误,该如何解决

    tomcat下部署两个工程时,只有一个可以访问,另一个出现404错误,该如何解决 在开发新项目的时候,有时候为了省时,直接把曾经做过的项目工程A拷贝成改名为B工程,然后再在B工程上进行功能的开发, 此 ...

  8. Centos7下的有多个版本的tomcat部署项目并访问

    在tomcat下部署项目,第一次访问成功.但是发现有一个页面没有成功加载,发现是部署时少了一些东西.也不想去找出具体少了什么,直接把原来的项目移除,重新加载项目.重启tomcat,这时惊喜来了. 重启 ...

  9. 转载:CentOS7下部署Django项目详细操作步骤

    部署是基于:centos7+nginx+uwsgi+python3+django 之上做的 文章转自:Django中文网        https://www.django.cn/article/sh ...

随机推荐

  1. undefined reference to `__sync_bool_compare_and_swap_4

    然后开始glibc的编译工作. 你必须设定march这个参数才行,要不然会出现“undefined reference to `__sync_bool_compare_and_swap_4′.”这个错 ...

  2. windows上使用clang编译程序

    环境:windows7,64位 1.下载并安装llvm,安装包里除了llvm,也有clang: http://releases.llvm.org/5.0.0/LLVM-5.0.0-win64.exe ...

  3. python3_unittest单元测试框架

    看见英文懵逼,强迫学习英语 The Unittest suppots test automation,sharing of setup and shutdown code of tests, aggr ...

  4. JS正则表达式从入门到入土(3)—— 范围类

    范围类 在使用正则表达式时,很多时候,我们会想要匹配a~z的所有字母,很多人想到,可以使用字符类[abcdefg...z],但是,这种方法需要输入所有需要匹配的字母.那么,有没有简单点的方法呢? 所幸 ...

  5. php项目代码 编码格式不对会大范围报错

    php项目代码 编码格式不对会大范围报错

  6. Python面试题之Python中__repr__和__str__区别

    看下面的例子就明白了 class Test(object): def __init__(self, value='hello, world!'): self.data = value >> ...

  7. 分享个基于 Node.js + React 的博客系统

    是使用 ES2015+ 特性写的,使用了 ThinkJS 框架,后台使用了 React. 完全使用 Markdown 来写文章,还可以把文章推送到团队博客系统中(团队博客也需要使用该系统). 项目地址 ...

  8. 20145231熊梓宏 《网络对抗》 实验9 Web安全基础实践

    20145231熊梓宏 <网络对抗> 实验9 Web安全基础实践 基础问题回答 1.SQL注入攻击原理,如何防御? •SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面 ...

  9. 20145231熊梓宏 《网络对抗》 实验5 MSF基础应用

    20145231熊梓宏 <网络对抗> 实验5 MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit就相当于是就是渗透攻击,其 ...

  10. Linux读书笔记1/2章

    linux的内核设计: 第一章 1.1Linux历史: 历经时间的考验,今天Unix已经发展成一个支持抢占式多任务.多线程.虚拟内存.换页.动态链接.TCP/Ip网络的现代化操作系统. 1.2追寻Li ...