0

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?

1
  • 1
    You really should consider using virtualenv to manage your packages in python. Several python installations is a known trouble... Jun 18, 2014 at 20:00

2 Answers 2

0

As per this answer, I installed pip2.6. Then I installed psycopg2 using the pip2.6 command and not pip like before:

sudo -E pip2.6 install psycopg2

Then it all worked

0

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.

$ virtualenv my_env26 -p python2.6
$ . my_env26/bin/activate
$ pip install whatever_i_want

$ virtualenv my_env27 -p python2.7
$ . my_env27/bin/activate
$ pip install another_packages

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

1
  • see my answer. i do not want to further complicate the configuration of my system by using another gadget
    – amphibient
    Jun 18, 2014 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.