Re: Using with Python 3, possible? how?

From: Leon Starr <leon_starr(at)modelint(dot)com>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Using with Python 3, possible? how?
Date: 2012-04-01 00:54:54
Message-ID: 434DA71B-B56F-4CE0-9D0D-D8FAA7EB6B0D@modelint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Thanks, Daniele, you've saved my weekend! (I think)

The magic word was 'easy_install3'! That doesn't work on my
installation, but it pointed me in the right direction.

I did a port search on py32 and saw all kinds of relevant goodies. After installing
distribute and ez_setup, I tried: which easy_install3, but no luck.

So I just did an easy_install again, but this time it fetched and placed correctly, in
the 32 path. And I was able to import psycopg2 okay from the 3.2.2 session.

BUT, there were a few dozen unsettling warnings generated during the easy_install and I am wondering if this is just
a 2->3 compatibility thing. How concerned should I be about this kind of stuff? Excerpt below:

- Leon
=======
psycopg/notify_type.c:226:5: warning: array index of '2' indexes past the end of
an array (that contains 1 elements) [-Warray-bounds]
PyTuple_SET_ITEM(args, 2, self->payload);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/tupleobject.h:62:37: note: instantiated from:
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
^
/opt/local/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m/tupleobject.h:27:5: note:
array 'ob_item' declared here
PyObject *ob_item[1];
^
In file included from psycopg/notify_type.c:27:
In file included from ./psycopg/psycopg.h:33:
./psycopg/config.h:71:13: warning: unused function 'Dprintf' [-Wunused-function]
static void Dprintf(const char *fmt, ...) {}
^
5 warnings generated.
psycopg/xid_type.c:254:9: warning: array index of '1' indexes past the end of an
array (that contains 1 elements) [-Warray-bounds]
PyTuple_SET_ITEM(args, 1, self->gtrid);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
========

On Mar 31, 2012, at 4:32 PM, Daniele Varrazzo wrote:

> 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

-----------------------------------------------------------------------------------------
Model Integration, LLC
Complex Application Requirements Analysis and Modeling
Expert UML/MDA Development, Training and Support

Leon Starr
Analyst / Model Engineer

+1 415 863 8649 office
+1 415 215 9086 cell

leon_starr(at)modelint(dot)com
www.modelint.com
www.miuml.org

www.linkedin.com/in/modelint
twitter.com/leon_starr

912 Cole Street, Suite 161
San Francisco, CA 94117
-----------------------------------------------------------------------------------------

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2012-04-01 16:46:07 Re: Using with Python 3, possible? how?
Previous Message Daniele Varrazzo 2012-03-31 23:32:28 Re: Using with Python 3, possible? how?