Skip to content

Instantly share code, notes, and snippets.

@Lzok
Last active April 29, 2024 18:17
Show Gist options
  • Save Lzok/e6791db882db612c1893886cb6909b42 to your computer and use it in GitHub Desktop.
Save Lzok/e6791db882db612c1893886cb6909b42 to your computer and use it in GitHub Desktop.
Commands to manage Python Virtual Environments with Pyenv

Install pyenv (Arch Linux) and add the paths to $PATH variable

sudo pacman -S pyenv

echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc && 
echo 'eval "$(pyenv init -)"' >> ~/.bashrc && 
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc &&
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.bashrc

List available Python versions to install on the system

pyenv install --list

Clone pyenv-virtualenv into pyenv plugins directory

git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

Install a Python version, for example the version 3.8.7

pyenv install 3.8.7

Create a virtualenvironment with the installed version

# pyenv virtualenv <version> <environment name>
pyenv virtualenv 3.8.7 environment387

List the virtualenvs

pyenv virtualenvs

Activate a virtualenv

# pyenv activate <environment name>
pyenv activate environment387

Deactivate a virtualenv

pyenv deactivate

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment