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
.