Attention

This documentation is under active development, meaning that it can change over time as we refine it. Please email help@massive.org.au if you require assistance.

Running Python Virtual Environments on M3#

M3 offers static Python builds which can be used to create a virtual environment (venv). A Python virtual environment effectively creates your own copy of Python, allowing you to install any Python packages you require. You are able to have multiple virtual environments, each with different packages installed; pip will manage your packages. You can learn more with this documentation on virtual environments.

Instructions for Python Virtual Environments (venvs) on M3#

The instructions below focus on creating a Python virtual environment using the static Python 3.6.2 module installed on M3.

your/install/location represents the location you are installing your virtual environment to. myPythonEnv represents the name of your environment.

Install your Python virtual environment#

# Set up your python venv - you need to use this path to avoid 'module load' and 'module unload'
# Change myPythonEnv to your environment name
/usr/local/python/3.6.2-static/bin/python3 -m venv your/install/location/myPythonEnv
# You will now have a Python venv installed into the directory your/install/location/myPythonEnv

Activating and deactivating your Python virtual environment#

# Activate the virtual environment - do this for each shell session.
# Change myPythonEnv to your environment name
source your/install/location/myPythonEnv/bin/activate

You will notice that when your virtual environment is activated, (myPythonEnv) will appear in the command prompt. For example:

(myPythonEnv) [user@m3-login]$

You need to source activate every time you start a new shell in order to use your virtual environment or install packages.

To deactivate your environment when you are done using it, run:

deactivate

You will notice (myPythonEnv) no longer appears in the command prompt.

Installing and updating Python packages in your virtual environment#

Pip is a Python package manager, which you can read more about on the pip home page. Use the following sample commands to install or update packages with pip.

# Upgrade pip to the latest version
pip install --upgrade pip

# To install packages to your virtual environment
pip install packageName
# To install a specific version of a package to your virtual environment
pip install packageName==versionNumber

# To update a package in your virtual environment to the newest version
pip install packageName --upgrade
# To update a package in your virtual environment to a specific version
pip install packageName==versionNumber

# To list your the packages installed in your virtual environment
pip list

If you encounter any problems when installing or using Python virtual environments, refer to our FAQs as you may be able to resolve them independently. If you are unable to resolve your problem or wish to give feedback on these instructions, please contact us at help@massive.org.au.