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: CA+mi_8bKpQkEFTsos2eJmQEATzCz1uHtYDJT1_cL-xh_kkg7tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
"easy_install3".

>        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
run:

python3 setup.py build
sudo python3 setup.py 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.

Cheers,

-- Daniele

In response to

Responses

Browse psycopg by date

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