Skip to content

Instantly share code, notes, and snippets.

@monocongo
Created July 3, 2019 14:11
Show Gist options
  • Save monocongo/5c3897e05f516baf3eb5e0e272942364 to your computer and use it in GitHub Desktop.
Save monocongo/5c3897e05f516baf3eb5e0e272942364 to your computer and use it in GitHub Desktop.
Python virtual environment basics

Configure Python development environment

Install pip, virtualenv, and virtualenvwrapper
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
$ rm get-pip.py
$ sudo pip install virtualenv virtualenvwrapper
Update .bashrc

To facilitate using Python virtual environments we'll add the below to the end of our existing ~/.bashrc file:

# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

Source the ~/.bashrc file to put the above environment variables and virtual environment settings into effect:

$ source ~/.bashrc
Python virtual environment

Create and activate a Python virtual environment:

$ mkvirtualenv myenv -p python3
$ workon myenv

Install required modules via requirements.txt file:

$ pip install -r requirements.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment