Tuesday, June 21, 2011

Setup VirtualEnv & Psycopg2 on Linux - redhat

We recently setup a boss of a computer at work to handle large analysis tasks. Luckily I got out of the initial setup, but when it came time to setup my virtualenv with the usual, I ran into a roadblock I had never encountered; pg_config cannot be found. So, here is the low down on how to setup your own virtualenv with psycopg2 on redhat.

-Create python virtualenv in your home director ("pymain" is what I call my virtualenv, you can call yours whatever you like):
virtualenv --no-site-packages pymain
-To activate your virtualenv, first navigate to the "bin" folder you just created:  

cd pymain/bin/ 
-Then activate using (you'll notice in the terminal the name of your virtualenv appears before yours after doing this): 

source activate
- Setup symbolic link to pg_config (so psycopg2 knows where to find it. THIS WAS THE ROADBLOCK): 

ln –s /usr/local/pgsql/bin/pg_config ~/pymain/bin/pg_config
-Install psycopg2:

easy_install psycopg2
-To deactivate your virtualenv simply type:

deactivate