I hit an issue with Python versions when trying to install pyarrow (which, at the time of writing, is not supported by Python 3.9). I use brew to manage my Python versions (see details here) and I wanted to keep the
python3 executable to the default version of Python (which is the latest version installed by brew), but still want to have the opportunity to easily use an older version of Python 3.X when needed.
python3 --version # Python 3.9.0 python3 -m venv /path/to/virtual/env # Creates a virtual environment using Python 3.9
The way I did this was through a bash alias, which basically allows you to create shortcuts to bash commands. (Here’s a link to an article that provides a brief overview of bash aliases.)
Provided that Python 3.8 is installed with brew, I alias
python3.8 to the brew command to launch Python 3.8,
$(brew --prefix)/firstname.lastname@example.org/bin/python3. To make the alias persist when I start new bash sessions I store it in my
alias python3.8="$(brew --prefix)/email@example.com/bin/python3" python3.8 --version # Python 3.8.6
This way I can create a virtual environment with Python 3.8 in a similar way to how I’d create it with the the python3 executable.
python3.8 -m venv /path/to/virtual/env # Creates a virtual environment using Python 3.8