Skip to content

Instantly share code, notes, and snippets.

@dunderrrrrr
Last active January 27, 2022 11:12
Show Gist options
  • Save dunderrrrrr/c3a6d5cba1b7320d6835b0fe995f5e6b to your computer and use it in GitHub Desktop.
Save dunderrrrrr/c3a6d5cba1b7320d6835b0fe995f5e6b to your computer and use it in GitHub Desktop.
virtualenv is a tool to create isolated Python environments.

virtualenv

virtualenv is a tool to create isolated Python environments.

https://pypi.org/project/virtualenv/#description

virtualenvwrapper

virtualenvwrapper is a set of extensions to Ian Bicking’s virtualenv tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.

https://virtualenvwrapper.readthedocs.io/en/latest/

Installation

sudo apt update 
sudo apt dist-upgrade 
sudo apt install python3-pip 
sudo apt install virtualenvwrapper 
pip3 install virtualenv

Add to ~/.bashrc and all your environments will be stored in ~/virtualenvs.

export WORKON_HOME=$HOME/virtualenvs
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

If using fish shell

pip install virtualfish

Add to ~/.config/fish/config.fish

eval (python -m virtualfish compat_aliases)

https://virtualfish.readthedocs.io/en/latest/plugins.html#id1
Reload your shell.

Create Python3 environment

user@host:~$ mkvirtualenv --python=/usr/bin/python3 yourenv
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/smegol/virtualenvs/yourenv/bin/python3
Also creating executable in /home/smegol/virtualenvs/yourenv/bin/python
Installing setuptools, pip, wheel...done.
(yourenv) user@host:~$
(yourenv) user@host:~$ pip freeze
(yourenv) user@host:~$ python --version
Python 3.6.5

Usage

lsvirtualenv - list your environments
workon <env_name> - activate environment
deactivate - deactivate your environment
rmvirtualenv <env_name> - remove environment

Boom, you done.

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