Python Virtual Environments
Python virtual environments are isolated installations of Python that can be used to run applications with their own individual Python package dependencies.
Python 3 includes native support for virtual environments via the venv
module.
- 1
Log in to a SSH session on your Opalstack server.
- 2
Execute the following command to create the virtual environment, changing
envname
to the name or full path of the Python virtual environment that you want to create:python3 -m venv envname
Python 2 virtual environments require the use of the virtualenv
package.
- 1
Log in to a SSH session on your Opalstack server.
- 2
Execute the following commands to install the
virtualenv
package:export PATH=$HOME/.local/bin:$PATH pip2.7 install --user -U pip pip2.7 install --user virtualenv
- 3
Execute the following command to create the virtual environment, changing
envname
to the name or full path of the Python virtual environment that you want to create:virtualenv --python=python2.7 envname
When you want to use the virtual environment interactively, you must first activate it with the following command, again changing envname
to the name or full path of your Python virtual environment.
source envname/bin/activate
When you are finished working with the environment, deactivate it by running the deactivate
command.