Whatbox Logo

Wiki > virtualenv

virtualenv is a tool to create isolated Python environments. On Whatbox, you could use virtualenv to install python packages that aren't included in the main global python installation.

Installation (Python 3)

Use these instructions if you are using a Python program or script that requires Python 3.

To execute the following commands you need to connect to your server via SSH.

  1. Create the Python 3 virtualenv

     /usr/bin/virtualenv -p python3 --system-site-packages ~/virtualenv/
    

    Optionally, you can use a different path besides ~/virtualenv/. If you use a different path, make sure to replace ~/virtualenv/ in any commands you may see on the Wiki.

  2. Activate virtualenv:

     source ~/virtualenv/bin/activate
    

Installation (Python 2, Python 2.7)

Python 2.7 is deprecated and will be removed from our servers in the future.

Use these instructions if you are using a Python program or script that requires Python 2.

To execute the following commands you need to connect to your server via SSH.

  1. Create a temporary Python 3 virtualenv

     /usr/bin/virtualenv -p python3 --system-site-packages ~/virtualenv2.7/python3
    
  2. Install an older version of virtualenv that supports Python 2.7

     ~/virtualenv2.7/python3/bin/pip install virtualenv==20.21.1
    
  3. Create the Python 2 virtualenv

     ~/virtualenv2.7/python3/bin/virtualenv -p python2 --system-site-packages ~/virtualenv2.7/
    

    Optionally, you can use a different path besides ~/virtualenv2.7/. If you use a different path, make sure to replace ~/virtualenv2.7/ in any commands you may see on the Wiki.

  4. Activate virtualenv:

     source ~/virtualenv2.7/bin/activate
    

Upgrading virtualenv

To upgrade your virtualenv, simply remove or rename ~/virtualenv/ and run the commands again. Please be careful to make sure that your programs and scripts do not store configuration files in this directory; if they do, move them out before deleting the directory, and move them back in when finished.

Other commands for virtualenv

To exit your virtualenv

        deactivate