Skip site navigation (1) Skip section navigation (2)

Re: Using with Python 3, possible? how?

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Leon Starr <leon_starr(at)modelint(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Using with Python 3, possible? how?
Date: 2012-03-31 23:32:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: psycopg
On Sat, Mar 31, 2012 at 11:06 PM, Leon Starr <leon_starr(at)modelint(dot)com> wrote:
> Greetings all, newbie here.  I'm trying to use the latest release of psycopg2 with Python3 and having no success so far.
> I'm on Mac OS X Lion (Xcode installed) and I have both 2.7 and 3.2.2 Python installations with 3 set as my default Python
> and these are both macports installations.
> So if I fire up my 2.7 IDLE session and do: import psycopg2
> it appears to work okay, i.e. no errors.  (And yes, I am sure it's the 2.7 session)
> But the same import in a 3.2.2 IDLE session tells me that no such module exists.
> Well, duh, of course, because psycopg2 is probably installed in the 2.7 site package
> directory.

Yes: Py2 and Py3 installation are separate (FWIW, each 2.x and 3.x is separate)

> My two part question is 1) can I use psycopg2 with Python3?  (The psycopg2 home site leads me to believe so)
> if so 2) How?  Here's what I've tried so far:
>        2a) easy_install would like to install in the 2.7 site install directory, okay, but it's already there, so no thanks
>                (should I try to force it into the 3.x site installation directory somehow?)

Yes: you should use easy_install provided with "Distribute" installed
on python3: on my system (ubuntu) it is available as the script

>        2b) I tried having easy_install load psycopg2 into a separate, empty directory which I put into my PYTHONPATH
>                variable, just to see what would happen.  Didn't work.  (See traceback below)

Of course: it gets linked with the wrong libpython.

>        2c) Should I somehow adjust my package search path in 3.2.2 to look in the 2.7 package directory?
>                What could possibly go wrong with that?  ;)

:) It would go wrong 2b style.

> So, should I be doing a, b, c or none of the above?  I eagerly await enlightenment and thank you for your time!

Either "easy_install3 psycopg2", if you find a way to get Distribute
for Python 3 on your system, or unpack the psycopg source tarball and

    python3 build
    sudo python3 install

You will need python-dev and libpq-dev packages installed, but if you
have installed psycopg on py2 via easy_install you should already have
them. Well, you may have py2-dev but not py3-dev... In case of error
check the missing .h at the beginning of the errors list and take a
look at the FAQ to see if they are helpful.


-- Daniele

In response to


psycopg by date

Next:From: Leon StarrDate: 2012-04-01 00:54:54
Subject: Re: Using with Python 3, possible? how?
Previous:From: Leon StarrDate: 2012-03-31 22:06:19
Subject: Using with Python 3, possible? how?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group