Knowledgebase: Python
Set Up Virtualenv
Posted by on 24 July 2012 11:58 PM

Before you can install custom python extensions via pip or easy_install, you will need to setup a Python virtual environment.  These instructions will help you to configure a python 2.6 virtual environment.  Before you can begin the process to configure one, you'll need ssh access enabled for your web hosting account if it isn't already.  You can request ssh access by either taking advantage of the "live chat" on the A Small Orange website or by submitting a support ticket.  Once you've successfully logged into your account via ssh and are presented with a shell prompt, you can setup the virtual environment in your account's home directory.  This is accomplished by using the virtualenv command like so:

virtualenv --python=python2.6 ~/.env

* This command may error on the first try, in which case, simply run it again and it should succeed on the second run.  This is nothing to worry about.  

Once that's done, you will have a .env directory with your python virtual environment in your home directory.  You generally will not need to worry about this directory, as sourcing the virtual environment will handle the backend work on your behalf.  Before you can use your virtual environment, it must be sourced.  You can add the following two lines to your ~/.bash_profile file (using a text editor such as nano or vi) to automatically set this up :

alias python='python2.6'

. ~/.env/bin/activate

You'll need to run that command each time you login.  Once run, your prompt will change to show that you are in your virtual environment and can run python commands as well as install python extensions to your local account which you can then use with python-based web applications such as Django.  

Some python modules may require a C compiler to install.  One such common extension is PIL, the Python Imaging Library.  Compiler access isn't available to customers, so you won't be able to install these.  In many cases, they will already be installed server wide.  If they are not, you'll need to request that they be installed by Tech Support by opening a support ticket.  

(7 vote(s))
This article was helpful
This article was not helpful

Help Desk Software by Kayako fusion
ERROR: This domain name (kb.asmallorange.com), does not match the domain name in the license key file help.asmallorange.com.

For assistance with your license, please contact the Kayako support team: https://support.kayako.com