首页 技术 正文
技术 2022年11月15日
0 收藏 590 点赞 4,522 浏览 3480 个字

Centos7下部署两套python版本并存

 

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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 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 24080lrwxrwxrwx 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.5lrwxrwxrwx 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.5lrwxrwxrwx 1 root root        8 Sep 27 19:40 pydoc3 -> pydoc3.5-rwxr-xr-x 1 root root       92 Sep 27 19:40 pydoc3.5lrwxrwxrwx 1 root root        9 Sep 27 19:40 python3 -> python3.5-rwxr-xr-x 2 root root 12309757 Sep 27 19:39 python3.5lrwxrwxrwx 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-configlrwxrwxrwx 1 root root       16 Sep 27 19:40 python3-config -> python3.5-configlrwxrwxrwx 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 listDEPRECATION: 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 -VPython 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]# pythonPython 2.7.5 (default, Nov  6 2016, 00:28:07)[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2Type "help""copyright""credits" or "license" for more information.>>>[root@qd-vpc-rec-dev01 Python-3.5.3]# python3Python 3.5.3 (default, Sep 27 2017, 19:38:56)[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linuxType "help""copyright""credits" or "license" for more information.>>> 也就是说,python指令表示的是2.7.5版本,python3指令表示的3.5.3版本。开发项目里具体使用那个版本的python,就使用对应的全路径的python指令。

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291