I tried to install psycopg2 for python2.6 but my system also has 2.7 installed.
I did
>sudo -E pip install psycopg2
Downloading/unpacking psycopg2
Downloading psycopg2-2.5.3.tar.gz (690kB): 690kB downloaded
Running setup.py (path:/private/var/folders/yw/qn50zv_151bfq2vxhc60l8s5vkymm3/T/pip_build_root/psycopg2/setup.py) egg_info for package psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2
building 'psycopg2._psycopg' extension
cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -arch x86_64 -arch i386 -pipe -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.3 (dt dec pq3 ext)" -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DPG_VERSION_HEX=0x09010B -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/local/Cellar/postgresql91/9.1.11/include -I/usr/local/Cellar/postgresql91/9.1.11/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-intel-2.7/psycopg/psycopgmodule.o
...
You can see that pip is associating psycopg2 with python2.7 during the install process. This pip install completed with a reported success result but when I ran a 2.6 script after that that imports psycopg2, it couldn't find it:
import psycopg2
ImportError: No module named psycopg2
How do I install psycopg2 for python2.6 when there is also 2.7 installed?
As per this answer, I installed pip2.6. Then I installed
psycopg2
using thepip2.6
command and not pip like before:sudo -E pip2.6 install psycopg2
Then it all worked
Use python virtualenvs.
Virtualenv is a box for python and bunch of packages. So instead of makins your system a mess by mixing python and system packages you are doing like this.
In that way you can have python environment with packages per project/per python version or grouped in any way you want. Profit is that you can remove this folder whenever you want very easly. It's harder when you mix system and python packages.
More about virtualenvs