Section C.2 Python Virtual Environment
There is a very good chance your system has a version of Python installed already since various other programs rely on it. You will be much happier if various Python programs you need for PreTeXt do not get entangled with your Python programs installed as system software. And if we need to help you debug some related problems we will ask you to work in a virtual environment anyway. We will follow a primer 1 that has been recommended by Brad Miller, founder of Runestone Interactive. See that page for more details.
These are condensed instructions without much explanation.
Do not install the old-school
Make a directory anywhere you like named
virtual-pythonand change into it.
python3 -m venv ptxmakes a virtual environment named
ptx. (Requires Python 3.6 or later.)
Done. But how do you use it?
To activate your virtual environment, be sure you are in the
virtual-pythondirectory. For Mac or Linux, with a bash shell go
source ptx/bin/activate (ptx) $
There are other scripts for other shells, take a look around.
For Windows, go
ptx/Scripts/activate.bat (ptx) >
Notice that your prompt has changed to remind you that now anything you do with Python will be “sandboxed” in this virtual environment and not get mixed up with your system Python.
Now you can do any Python-related task using your virtual environment, and can change directories if desired.
When you are finished with your virtual environment, on Mac or Linux with a bash shell you simply go
(ptx) $ deactivate $
For Windows, similarly
(ptx) > deactivate >