pyenv set up multiple versions of python environment

installation

Quick installation

# mac
$ brew install pyenv

Source Installation

# Check out pyenv
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
 
# Define environment variable PYENV_ROOT
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

# Add pyenv init to your shell
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

# Restart your shell
exec "$SHELL"

# Just run!
$ pyenv -v
pyenv 1.2.17-1-g89786b90

note:

  • Zsh: modify the ~/.zshrcfile instead ~/.bash_profile.
  • Ubuntu, Fedora: modify the ~/.bashrcfile instead ~/.bash_profile.

use

Install python version needed:

# install python
$ pyenv install 2.7.8

$ pyenv install 3.8.2

$ pyenv versions
  system
  2.7.8
* 3.8.2 (set by /Users/youshu/.pyenv/version)

Generally there is a 2.7, a 3.8 is enough.

If you are unsure which version support, you can view pyenv support the installation of Python version are:

$ pyenv install --list

Use the specified version of Python:

$ pyenv local 2.7.8
$ python -V
Python 2.7.8

Use localcommand in the current shell just switch to the specified version, if required effect globally, we need to use the globalcommand:

$ pyenv global 3.8.2
$ python -V
Python 3.8.2

Using the latest version

If you need a version not supported pyenv list, you can manually add. ~/.pyenv/plugins/python-build/share/python-build/Directory is stored in the various versions of the download, the file name is the name of the version of Python.

$ ls ~/.pyenv/plugins/python-build/share/python-build/
2.1.3                  3.3.6                  anaconda-1.6.1         ironpython-2.7.7       miniconda3-3.9.1       pypy-5.1               pypy3.3-5.2-alpha1 
...

Here are the contents 3.8.2:

$ cat ~/.pyenv/plugins/python-build/share/python-build/3.8.2
#require_gcc
prefer_openssl11
export PYTHON_BUILD_CONFIGURE_WITH_OPENSSL=1
install_package "openssl-1.1.0j" "https://www.openssl.org/source/openssl-1.1.0j.tar.gz#31bec6c203ce1a8e93d5994f4ed304c63ccf07676118b6634edded12ad1b3246" mac_openssl --if has_broken_mac_openssl
install_package "readline-8.0" "https://ftpmirror.gnu.org/readline/readline-8.0.tar.gz#e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461" mac_readline --if has_broken_mac_readline
if has_tar_xz_support; then
  install_package "Python-3.8.2" "https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz#2646e7dc233362f59714c6193017bb2d6f7b38d6ab4a0cb5fbac5c36c4d845df" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
else
  install_package "Python-3.8.2" "https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz#e634a7a74776c2b89516b2e013dda1728c89c8149b9863b8cea21946daf9d561" ldflags_dirs standard verify_py38 copy_python_gdb ensurepip
fi

help

$ pyenv -h
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   --version   Display the version of pyenv
   commands    List all available pyenv commands
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   local       Set or show the local application-specific Python version
   prefix      Display prefix for a Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall a specific Python version
   version     Show the current Python version and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

reference

1、pyenv/pyenv: Simple Python version management
https://github.com/pyenv/pyenv

Guess you like

Origin www.cnblogs.com/52fhy/p/12524372.html