Two sets of Python versions coexist under CENTOS7

Source: Internet
Author: User

Requirements Description:
The centos7.2 system has its own python2.7 version on the development machine, but the development project uses the python3.5 version, in order to ensure the normal operation of the CentOS system, and save the machine resources (do not want to apply for another development machine deployment python3.5), so need to install PYT The development environment in which hon3.5 and python2.7 coexist. The specific operation record is as follows:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 666768697071 1)安装相关包[[email protected] ~]# yum -y install epel-release[[email protected] ~]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel 2) 编译安装python3.5[[email protected] ~]# yum -y install xz[[email protected] ~]# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz[[email protected] ~]# tar xf Python-3.5.3.tar.xz -C /usr/local/src/[[email protected] ~]# cd /usr/local/src/Python-3.5.3[[email protected] Python-3.5.3]# ./configure --prefix=/usr/local/python3[[email protected] Python-3.5.3]# make && make install从 Python 3.4 开始就已经自带了pip和easy_install(setuptools 包带的命令) 包管理命令,你可以在 /usr/local/python3/bin/目录下看到,查看一下已经安装的扩展包:[[email protected] 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[[email protected] Python-3.5.3]# /usr/local/python3/bin/pip3 listDEPRECATION: The default formatwill switch to columns inthe future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) inyour pip.conf under the [list] section) to disable this warning.pip (9.0.1)setuptools (28.8.0)-----------------------------------------------------------------------------------------------------------------------------如果要更新pip,操作如下:[[email protected] Python-3.5.3]# /usr/local/python3/bin/pip3 install --upgrade pip[[email protected] Python-3.5.3]# /usr/local/python3/bin/pip3 list-----------------------------------------------------------------------------------------------------------------------------3)创建软连接[[email protected] Python-3.5.3]# ln -s /usr/local/python3/bin/python3 /usr/bin/python34) 执行python -V查看Python是否安装成功。[[email protected] Python-3.5.3]# python3 -VPython 3.5.3自带的版本为:[[email protected] Python-3.5.3]# python -V         Python 2.7.5[[email protected] Python-3.5.3]# which python/usr/bin/python[[email protected] Python-3.5.3]# which python3/usr/bin/python3[[email protected] 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" formoreinformation.>>>[[email protected] 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"formoreinformation.>>>也就是说,python指令表示的是2.7.5版本,python3指令表示的3.5.3版本。开发项目里具体使用那个版本的python,就使用对应的全路径的python指令。

Two sets of Python versions coexist under CENTOS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.