Python Virtual Environments

Quick reference to python virtual environments

Install the virtualenv python module module. Be sure to use the correct pip version

pip3 install virtualenv

Create a virtualenv

virtualenv devenv

Activate a virtualenv

-> source ~/devenv/bin/activate

Install a module in the virtualenv

-> pip3 install <module>

Deactivate a virtualenv

->  deactivate

An entire workflow to create a virtualenv to use SWIFT to interact with Openstack ObjecStorage would be like this:

On Mac:
- pip install virtualenv
- virtualenv swift-venv
- source swift-venv/bin/activate
- pip install python-swiftclient
- pip install python-keystoneclient
- To come out of virtualenv, type deactivate

The swift command would be in /Users/jdoe/swift-venv/bin/swift

Reference

https://docs.python.org/3/tutorial/venv.html

Last updated