Update 2009-11-02: Well I am dumb-- psycopg2 can be installed with pip/easy_install. The reason I got the error before was because I didn't have the required dependencies installed. On Ubuntu, I used apt-get build-dep
. So, here's the summary:
Update 2009-11-11: My update doesn't work. See comments #4 and #5 below.
Update 2010-05-17: Here is what finally worked for me using Python 2.6 on Ubuntu 10.04 Lucid Lynx using virtualenv 1.4.8 and pip 0.7.1. Thanks to Daniel for the final piece of the solution.
Update 2011-05-13: Looks like the mx+virtualenv issue has been reported and fixed to be released in 2.4.2. via @psycopg's tweet
Update 2011-11-05: psycopg2 2.4.2 has been released with the mxDateTime fix so the install is very easy now.
Install dependencies
$ sudo apt-get build-dep python-psycopg2
Install pyscopg2 in a virtualenv
$ virtualenv --no-site-packages myenv
$ source myenv/bin/activate
$ pip install psycopg2
No longer needed: $ easy_install -i http://downloads.egenix.com/python/index/ucs4/ egenix-mx-base
*** THE REST OF THIS POST DESCRIBES MY INITIAL OUTDATED SOLUTION. ***
I recently starting using virtualenv for creating isolated Python environments. Virtualenv has made it easy to manage different Python configurations for different websites, but I was slowed down a bit trying to use psycopg2, the Python-PostgreSQL database adapter, with virtualenv after upgrading to Ubuntu 9.04 Jaunty Jackalope.
Currently, virtualenv (1.3.3) doesn't find Ubuntu Jaunty's Python packages. In Ubuntu Jaunty, the default Python version changed from 2.5 to 2.6. More importantly, the site-packages
directory was changed to dist-packages
. Prior to Ubuntu 9.04, Ubuntu's Python packages, such as python-psycopg2
, were installed to /usr/lib/python2.5/site-packages
. Now Ubuntu's Python packages are installed to /usr/lib/python2.6/dist-packages
. (See this discussion at the virtualenv group for more information.)
As a result of this change, virtualenv (as of 1.3.3) doesn't find Ubuntu's Python packages installed using apt-get
. My solution was to create symlinks to the desired packages and egg-info files in site-packages
. I'm not sure if this is the proper way to handle this. If there is a better solution, please let me know. One advantage of using this method is that I don't need to clutter my virtualenv with all the packages that have accumulated in my global site-packagesdist-packages
.
Install easy_install, pip, and virtualenv
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install -U pip
sudo pip install -U virtualenv
Install Ubuntu's psycopg2 package
sudo apt-get install python-psycopg2
Symlink the psycopg2 (and mxDateTime) files
sudo mkdir /usr/lib/python2.6/site-packages
sudo ln -s /usr/lib/python2.6/dist-packages/psycopg2 /usr/lib/python2.6/site-packages
sudo ln -s /usr/lib/python2.6/dist-packages/psycopg2-2.0.8.egg-info /usr/lib/python2.6/site-packages
sudo ln -s /usr/lib/python2.6/dist-packages/mx /usr/lib/python2.6/site-packages
Create a virtualenv
virtualenv myenv
Check what's available
pip freeze -E myenv
Results:
psycopg2==2.0.8
wsgiref==0.1.2
Note: you might wonder why I didn't do a pip install -E myenv psycopg2
. I tried this, but got an error. Maybe psycopg2 doesn't support pip/easy_install? Here is my error message:
Downloading/unpacking psycopg2
Downloading psycopg2-2.0.11.tar.gz (255Kb): 255Kb downloaded
Running setup.py egg_info for package psycopg2
error: No such file or directory
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
error: No such file or directory
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in ./pip-log.txt
Complete output from command temp/bin/python /usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py install -E temp psycopg2 temp ___VENV_RESTART___:
----------------------------------------
Traceback (most recent call last):
File "/usr/local/bin/pip", line 3, in
pip.main()
File "/usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py", line 926, in main
return command.main(initial_args, args[1:], options)
File "/usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py", line 258, in main
restart_in_venv(options.venv, site_packages, complete_args)
File "/usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py", line 1009, in restart_in_venv
call_subprocess([python, file] + args + [base, '___VENV_RESTART___'])
File "/usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py", line 3643, in call_subprocess
% (command_desc, proc.returncode))
pip.InstallationError: Command temp/bin/python /usr/local/lib/python2.6/dist-packages/pip-0.4-py2.6.egg/pip.py install -E temp psycopg2 temp ___VENV_RESTART___ failed with error code 1