Gangmax Blog

The Python RVM equivalent: pyenv

I was wondering if there is something in the Python world just like RVM in the Ruby world. So I get pyenv.

Here is the instructions to install pyenv(from here):

1
2
3
4
5
6
7
8
9
# Get the pyenv source code.
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# Put the following lines into the end of the "~/.bashrc" or "~/.zshrc" file.
# pyenv.
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi

How to use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# First open a new terminal to make the change takes effect. Then run
# the following commands.
# 1. Run the following command to know what Python versions can be
# installed. It's A LOT!
pyenv install -l
# 2. Install one.
pyenv install 3.8.2
# 3. Make the installation takes effect.
pyenv rehash
# 4. Check the current installed environments and which one is taking effect.
pyenv versions
# 5. Use the specific environment.
pyenv local 3.8.2
# 6. Install a package for the current environment.
pip list
pip install paramiko
pip list

Edited on 2020-03-18.

Comments