Setup multiple python version by pyenv

  • Check out Pyenv where you want it installed.
    • A good place to choose is $HOME/.pyenv (but you can install it somewhere else):
 git clone https://github.com/pyenv/pyenv.git ~/.pyenv
  • Optionally, try to compile a dynamic Bash extension to speed up Pyenv.
    • Don’t worry if it fails; Pyenv will still work normally:
 cd ~/.pyenv && src/configure && make -C src
  • Configure your shell’s environment for Pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc

echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc

echo 'eval "$(pyenv init --path)"' >> ~/.bashrc

exec $SHELL -l
Check available python version to install
pyenv install --list
  • install dedicate python version you want
pyenv install 3.6.9 -v
pyenv install 2.7.18 -v
  • change python version
pyenv global 3.6.9
  • double check if everything was correct
pyenv --versions
which python
python --version

Ref:

Search

    Table of Contents