Python Virtual Envs

From XPUB & Lens-Based wiki
Revision as of 14:29, 20 February 2020 by Andre Castro (talk | contribs) (Created page with "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 pac...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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