1. Install Python (in this case, python 3.7)
  2. Set up venv
  3. Exiting venv

Before writing your code, you should make sure that your python environment is easily portable to other machines. None of that “Works on my machine” nonsense!

Instead, we are going to use venv, a “virtual environment” for your python development.

Install Python (in this case, python 3.7)

This was tested in Ubuntu 16.04.

# install python
sudo apt-get install -y python3.7 python3.7-venv

Set up venv

There are only a few lines that need to be uncommented:

# install venv
python3.7 -m venv env
# activate venv
source env/bin/activate
# install pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
# upgrade pip to latest version
pip install --upgrade pip
# (optional) install any requirements of your current app in this venv
pip install -r requirements.txt

Now you are ready to start coding!

# now we can use python instead of python3.7 as the executable name, because venv will take care of selecting the right version for us

Exiting venv

#simply type