Python Virtual Envs

From XPUB & Lens-Based wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Python virtual environments consists of a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

Read more on https://docs.python.org/3/tutorial/venv.html

set the venv by

  • opening the terminal in the python project directory
  • create the venv, with the python version you wish, we'll use 3.7
python3.7 -m venv ./venv 
  • activate the environment and should see (venv) in the shell prompt
source venv/bin/activate
  • now you can use pip to install or python to run the script, which will be always referencing to the python version you used to install the vev
  • later on when you wish to close the venv run:
deactivate