Software – Python Virtual Environments
Python is available across all systems, The version of Python will be different depending on the system’s OS.
This enables you to build your python environment without root access, as well as making it much more portable across systems, plus it’s really simple to do.
Python Versions
System | Version | Notes |
CentOS 7 | Python 2.7 | Default |
CentOS 7 | Python 3.6 | python3 |
CentOS 7 | Python 3.8 | source /opt/rh/rh-python38/enable |
Rocky 9 | Python 3.9 | Default |
Fedora 38 | Python 3.11 | Default |
Fedora 40 | Python 3.12 | Default |
Any | Any | BYOP (See below) |
Custom Python Versions
If you require a specific version of Python then you can use PyEnv to locally download most specific python versions. See more at PyEnv on Github.
Create Environment
Python 3
To create a Python3 virtual environment
python3 -m virtualenv <environment_name>
or if that doesn’t work
python3 -m venv <environment_name>
Python 2.7 (Deprecated)
To create a Python2 virtual environment (CentOS 7 Only)
python2 -m virtualenv <environment_name>
Python 2.7 has been deprecated and no longer receives official support, you should migrate your code-base to python3 for continued working support. We cannot guarantee that python2 will continue to be available.
If you need to run a python2 virtual environment on the Fedora Desktops, then first create the Environment on a CentOS 7 based system and activate it on Fedora. However, we cannot recommend this work-around.
Use the Environment
Source the environment for your shell
source <environment_name>/bin/activate or source <environment_name>/bin/activate.csh or source <environment_name>/bin/activate.fish
then you can run pip/pip3 etc as you wish.
Upgrade the Environment
If the version of Python has updated on the system and is causing your envrionment to not load try this command in the shell
python3 -m venv --upgrade <environment_name>
Leave the Environment
deactivate
Known Issues with Virtual Environments
People with large 1GB+ environments especially when it’s lots of little files sometimes find that the activation can take a long time.
BYOP – Bring Your Own Python
Please see here: https://github.com/pyenv/pyenv
More details to come.