Pyenv managing multiple versions of Python

Source: Internet
Author: User
Tags rehash

It's not easy to install different versions of Python, and it's even harder to switch between different versions of Python on the same host! We all know that multi-version will cause mutual interference, but can not not solve it??

Exact answer: No, because there is a good helper to learn Python pyenv to manage different versions of Python!


First, to install the pyenv:

The installation steps are also simple, just download it locally on GitHub, and then execute the following commands separately

[[Email protected]_ali_sz_120 ~]# git clone https://github.com/yyuu/pyenv.git ~/.pyenv



[Email protected]_ali_sz_120 ~]# echo ' Export pyenv_root= "$HOME/.pyenv" ' >>/etc/profile[[email protected]_ali_ sz_120 ~]# echo ' export path= ' $PYENV _root/bin: $PATH "' >>/etc/profile[[email protected]_ali_sz_120 ~]# Echo ' eval ' $ (pyenv init-) "' >>/etc/profile

Make the above configuration effective:

[Email protected]_ali_sz_120 ~]# source/etc/profile


Here Pyenv has been installed, we can use--HELP to see how the pyenv is used:

[[email protected]_ali_sz_120 ~]# pyenv --helpusage: pyenv <command>  [<args>] Some useful pyenv commands are:   commands    list  all available pyenv commands   local        Set or show the local application-specific Python version    global      Set or show the global Python  version   shell       set or show the  Shell-specific python version   install     install a  python version using python-build   uninstall   uninstall  a specific Python version   rehash       Rehash pyenv shims  (run this after installing executables)    version      show the current python version and its origin    versions    List all Python versions available  to pyenv   which       display the full  Path to an executable   whence      list all  Python versions that contain the given executableSee  ' Pyenv help  <command> '  for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme


Second, the use of pyenv:

First, you can use the install command to view a Python-supported version

[[Email protected]_ali_sz_120 ~]# pyenv install--listavailable versions:2.1.3 2.2.3 2.3.7 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 ...


We have chosen two versions here to test the installation of multiple versions of Python on the same host:

[Email protected]_ali_sz_120 ~]# pyenv install-v 3.6.0 [[email protected]_ali_sz_120 ~]# pyenv versions* System (set by /root/.pyenv/version) 3.6.0 [[Email protected]_ali_sz_120 ~]# pyenv install-v 2.7.13 [[Email protected]_ali_sz_120 ~]# P Yenv versions* System (set by/root/.pyenv/version) 2.7.13 3.6.0

Now that we have three Python versions of this system, here's how to switch versions, and note that ' * ' indicates the version you're currently using. You can switch versions via global:

(here may worry about the switch version, the version of the dependency will not be switched together, this does not fear related dependencies will follow the switch, so there is no need to worry about the interaction between the different versions of the system, the following version of the PIP will also change with the Python version changes)

[Email protected]_ali_sz_120 ~]# pyenv Global 3.6.0[[email protected]_ali_sz_120 ~]# pyenv versions System 2.7.13* 3.6. 0 (set by/root/.pyenv/version) [[Email protected]_ali_sz_120 ~]# pip--versionpip 9.0.1 from/root/.pyenv/versions/3.6.0 /lib/python3.6/site-packages (Python 3.6) [[Email protected]_ali_sz_120 ~]# pyenv Global 2.7.13[[email Protected]_ali_ sz_120 ~]# pyenv versions system* 2.7.13 (set by/root/.pyenv/version) 3.6.0[[email protected]_ali_sz_120 ~]# pip--vers Ionpip 9.0.1 from/root/.pyenv/versions/2.7.13/lib/python2.7/site-packages (python 2.7)

Finally cut back to the system version:

[Email protected]_ali_sz_120 ~]# pyenv Global System



If you want to delete the Python version, you can use the uninstall command:

[Email protected]_ali_sz_120 ~]# pyenv Uninstall 2.7.13


Pyenv managing multiple versions of Python

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.