Skip to content

Instantly share code, notes, and snippets.

@bashtheshell
Created July 13, 2020 00:10
Show Gist options
  • Save bashtheshell/6c4336c5d049cf70f72e14505418d645 to your computer and use it in GitHub Desktop.
Save bashtheshell/6c4336c5d049cf70f72e14505418d645 to your computer and use it in GitHub Desktop.
A quick primer on setting up virtual environment with Python 3

Python3 Virtual Environment Cheat Sheet:

Oftentimes, I'd forget how to set up a quick virtual environment (virtualenv) with Python3 when I'd find myself working on a new Python script after months of inactivity.

Before running the command below, it's assumed you have Python 3 already installed and you're in a new directory. In this example, we'll use project_dir as a new directory which is located in the current user's home directory.

mkdir ~/project_dir
cd ~/project_dir
python3 -m venv venv
source ./venv/bin/activate
pip install --upgrade pip

After the source command, you'd see that your current shell prompt (PS1) woudld be prepended with (venv). To exit the virtual environment, just run deactivate.

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