Python series (v) deploy multiple Python versions in centos6.x

Source: Internet
Author: User
Tags custom name virtual environment virtualenv

Bo main QQ:819594300

Blog address:http://zpf666.blog.51cto.com/

Have any questions friends can contact Bo Master, Bo Master will help you answer, thank you for your support!

Deploying Python multiple Versions using the Pyenv+virtualenv method

PYENVVS virtualenv

pyenv is for the Python version of the management, by modifying the way the environment variables implemented;

virtualenv is the multi-version management of Python packages, by installing a Python package into a module as a Python package virtual environment, switching directories to enable switching between different package environments.

pyenv principle

pyenv The beauty of this is that it does not use a high-coupling approach that uses different $PATH to implant different shells, but simply inserts a shim path (shims) at the front of the $PATH:

~/.pyenv/shims:/usr/local/bin:/usr/bin:/bin . All lookups of the Python executable are first intercepted by this shims path, thereby overhead the system path behind.

pyenv installation Use (installation using the network Yum source)

The following begins the formal installation:

1 ) Check the system version

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/94/C2/wKioL1kNdQ3iudF3AAEOL8NwQXo306.jpg "title=" Image001.jpg "alt=" Wkiol1kndq3iudf3aaeol8nwqxo306.jpg "/>

2 ) Install dependent packages

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/94/C2/wKioL1kNdMuh2nugAADOgKmLsUE761.jpg "style=" float : none; "title=" image002.jpg "alt=" Wkiol1kndmuh2nugaadogkmlsue761.jpg "/>

The contents are as follows:

Yum-y install gcc python-devel readline readline-devel readline-static opensslopenssl-devel openssl-static sqlite-devel Bzip2-devel Bzip2-libspython-setuptools

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/94/C2/wKioL1kNdMuwBULoAABmuOWRFsk756.jpg "style=" float : none; "title=" image003.jpg "alt=" Wkiol1kndmuwbuloaabmuowrfsk756.jpg "/>

3 ) Install pyenv

pyenv git tools are required and you need to install the Git tool first

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M01/94/C2/wKioL1kNdMzCjD1JAABq3xYwufY434.jpg "style=" float : none; "title=" image004.jpg "alt=" Wkiol1kndmzcjd1jaabq3xywufy434.jpg "/>

pyenv automated installation tools are available to perform command installation:

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M01/94/C2/wKioL1kNdMzyEmBEAABkuYKTJ7Q208.jpg "style=" float : none; "title=" image005.jpg "alt=" Wkiol1kndmzyembeaabkuyktj7q208.jpg "/>

The address is as follows:
Curl-l https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer| Bash

There is also a Web site, also provides pyenv automatic installation of tools, the two sites are the same, whichever is OK.

Curl-lhttps://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer | Bash

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/94/C2/wKiom1kNdM2xKAjhAADsQRxlDHs802.jpg "style=" float : none; "title=" image006.jpg "alt=" Wkiom1kndm2xkajhaadsqrxldhs802.jpg "/>

The above three lines will appear at the end of the installation.

To see if the installation was successful, execute the following command:

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/94/C2/wKiom1kNdM3R3baJAACHDNMow1E858.jpg "style=" float : none; "title=" image007.jpg "alt=" Wkiom1kndm3r3bajaachdnmow1e858.jpg "/>

If the value returned is 0, the installation is successful.

If you want to install manually, you can execute this command:

Check out the pyenv to the directory you want to install. The recommended path is: $HOME/.pyenv

$ cd

$ git clone git://github.com/yyuu/pyenv.git.pyenv

4 ) Add environment variable

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M02/94/C2/wKioL1kNdM7TQEbhAABkubrqGpo892.jpg "style=" float : none; "title=" image008.jpg "alt=" Wkiol1kndm7tqebhaabkubrqgpo892.jpg "/>

This directory is dedicated to bash information for the current user bash shell, which is read when logging in and every time a new shell is opened

Add the following lines at the end:

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/94/C3/wKiom1kNdM_ibXqfAAFsdWjFbvk706.jpg "style=" float : none; "title=" image009.jpg "alt=" Wkiom1kndm_ibxqfaafsdwjfbvk706.jpg "/>

The contents are as follows:

Export pyenv_root= "${home}/.pyenv"

If [-D "${pyenv_root}"]; Then

Exportpath= "${pyenv_root}/bin:${path}"

Eval "$ (pyenv init-)"

Fi

Once added, let it take effect immediately:

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/94/C2/wKioL1kNdM_QKp7qAACw2IbFSiE383.jpg "style=" float : none; "title=" image010.jpg "alt=" Wkiol1kndm_qkp7qaacw2ibfsie383.jpg "/>

at this point, the pyenv installation is complete, and then see what Python versions are available to install .

650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M01/94/C3/wKiom1kNdNDACYikAAJxlgJvRcE488.jpg "style=" float : none; "title=" image011.jpg "alt=" Wkiom1kndndacyikaajxlgjvrce488.jpg "/>

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M01/94/C2/wKioL1kNdNHywuSoAAIFS46FGiU892.jpg "style=" float : none; "title=" image012.jpg "alt=" Wkiol1kndnhywusoaaifs46fgiu892.jpg "/>

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M02/94/C2/wKioL1kNdNGiUKUyAAF5E7F_N3g963.jpg "style=" float : none; "title=" image013.jpg "alt=" Wkiol1kndngiukuyaaf5e7f_n3g963.jpg "/>

5 Let's take a look at what version of Python centos6.5 is installed by default:

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M02/94/C3/wKiom1kNdNLz0JE9AACteBs-qUw484.jpg "style=" float : none; "title=" image014.jpg "alt=" Wkiom1kndnlz0je9aactebs-quw484.jpg "/>

As you can see, the default installation of centos6.5 is version 2.6.6.

Now let's install a 3.6.1 version Try it:

650) this.width=650; "src=" https://s2.51cto.com/wyfs02/M02/94/C2/wKioL1kNdNKA_3eiAAE99bUNC2U053.jpg "style=" float : none; "title=" image015.jpg "alt=" Wkiol1kndnka_3eiaae99bunc2u053.jpg "/>

6 ) Create a virtual environment

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/94/C3/wKiom1kNdNPibMHoAAExVLfUQCY519.jpg "style=" float : none; "title=" image016.jpg "alt=" Wkiom1kndnpibmhoaaexvlfuqcy519.jpg "/>

Where my-virtual-env-3.6.1 is a custom name, you can customize it yourself.

7 ) lists the current virtual environment

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M00/94/C3/wKiom1kNdNPyLIbHAADFdVZLMAU292.jpg "style=" float : none; "title=" image017.jpg "alt=" Wkiom1kndnpylibhaadfdvzlmau292.jpg "/>

8 ) To activate the virtual environment

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/94/C2/wKioL1kNdNSS_eT-AADdZOYD3lk730.jpg "style=" float : none; "title=" image018.jpg "alt=" Wkiol1kndnss_et-aaddzoyd3lk730.jpg "/>

9 after activating the virtual environment, you need to execute the following command to update the database

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M00/94/C2/wKioL1kNdNSAqVu9AACmGquKpkY669.jpg "style=" float : none; "title=" image019.jpg "alt=" Wkiol1kndnsaqvu9aacmgqukpky669.jpg "/>

Then go directly to Python to view:

650) this.width=650; "src=" https://s1.51cto.com/wyfs02/M01/94/C3/wKiom1kNdNTD1orIAADVTiWk4Hk759.jpg "style=" float : none; "title=" image020.jpg "alt=" Wkiom1kndntd1oriaadvtiwk4hk759.jpg "/>

Ten ) To view the version that is currently in use

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M01/94/C2/wKioL1kNdNWRytivAAEg6ZJIqUQ600.jpg "style=" float : none; "title=" image021.jpg "alt=" Wkiol1kndnwrytivaaeg6zjiquq600.jpg "/>

Note: Asterisks indicate the version that is currently in use

One ) exit the virtual environment

650) this.width=650; "src=" https://s4.51cto.com/wyfs02/M02/94/C3/wKiom1kNdNWAmWjIAADKNUn68LU134.jpg "style=" float : none; "title=" image022.jpg "alt=" Wkiom1kndnwamwjiaadknun68lu134.jpg "/>

As can be seen, our real environment is still 2.6.6, while the virtual environment is 3.6.1 version.

A ) Delete the virtual environment

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/94/C2/wKioL1kNdNaT44u5AADwrsROIqg948.jpg "style=" float : none; "title=" image023.jpg "alt=" Wkiol1kndnat44u5aadwrsroiqg948.jpg "/>

Appear one? , enter a Y and continue.

If you want to switch between two versions , enter it every time you want to use the 3.6.1 version:

Pyenv Activate my-virtual-env-3.6.1

If you enter Python again, you can go to the 3.6.1 version.

If you do not want to use the 3.6.1 version, exit and use:

pyenvdeactivate The command exits and you can use our version 2.6.6.

What if you don't want to be so troublesome?

Good, then create a virtual environment to run the 2.6.6 version.

650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M01/94/C3/wKiom1kNdNaDVckEAABnu_PACiE578.jpg "style=" float : none; "title=" image024.jpg "alt=" Wkiom1kndnadvckeaabnu_pacie578.jpg "/>

Description: If you do not specify a python version, the current environment Python version is used by default.

Take a look at all the current virtual environments:

650) this.width=650; "src=" https://s5.51cto.com/wyfs02/M01/94/C2/wKioL1kNdNaivXtiAADt4PSx2-8698.jpg "style=" float : none; "title=" image025.jpg "alt=" Wkiol1kndnaivxtiaadt4psx2-8698.jpg "/>

To activate the 2.6.6 virtual environment:

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M00/94/C3/wKiom1kNdNeyg43lAADlGIn5u8s972.jpg "style=" float : none; "title=" image026.jpg "alt=" Wkiom1kndneyg43laadlgin5u8s972.jpg "/>

Update the database:

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/94/C3/wKiom1kNdNeQmx1hAACv77b0fmQ793.jpg "style=" float : none; "title=" image027.jpg "alt=" Wkiom1kndneqmx1haacv77b0fmq793.jpg "/>

At this point, 2.6.6 and 3.6.1 have two virtual environments, and now it's easier to switch:

650) this.width=650; "src=" https://s3.51cto.com/wyfs02/M02/94/C2/wKioL1kNdNeA4fS6AAISmOXGQPQ147.jpg "style=" float : none; "title=" image028.jpg "alt=" Wkiol1kndnea4fs6aaismoxgqpq147.jpg "/>

Just need these two commands can be in the current real environment to switch back and forth two versions, is not very convenient.

Add an additional knowledge point description:

If you have only 3.6.1 Virtual environments without creating a 2.6.6 virtual environment, when you perform:

Pyenvlocal my-virtual-env-3.6.1

That is: in the current environment, switch 3.6.1 version, switch over is no problem, mainly you think about not when you want to use the 2.6.6 version? Can't cut back, because there is no 2.6.6 virtual environment, you can not execute:

pyenvlocal my-virtual-env-2.6.6 This command, at this time you go to create a new 2.6.6 virtual environment, it is too late, the concrete solution is to go to ~/.BASHRC inside to add a few new lines delete or comment, Then delete the 3.6.1 virtual environment, and finally restart the system to restore the python2.6.6 version of the real environment, and then you re-read the above experiment again, remember to create two virtual environments, so it is convenient to switch back and forth.

This article is from the IT Technical Assistant blog, so be sure to keep this source http://zpf666.blog.51cto.com/11248677/1922670

Python series (v) deploy multiple Python versions in centos6.x

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.