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

Using with Python 3, possible? how?

From: Leon Starr <leon_starr(at)modelint(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Using with Python 3, possible? how?
Date: 2012-03-31 22:06:19
Message-ID: (view raw or whole thread)
Lists: psycopg
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

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?)
	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)
	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?  ;)

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

- Leon Starr

(from 3.2.2 IDLE session)
>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/starr/SDEV/Python/Site_P3/psycopg2-2.4.5-py2.7-macosx-10.7-x86_64.egg/psycopg2/", line 67, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/starr/SDEV/Python/Site_P3/psycopg2-2.4.5-py2.7-macosx-10.7-x86_64.egg/psycopg2/, 2): Symbol not found: _PyBuffer_Type
  Referenced from: /Users/starr/SDEV/Python/Site_P3/psycopg2-2.4.5-py2.7-macosx-10.7-x86_64.egg/psycopg2/
  Expected in: flat namespace
 in /Users/starr/SDEV/Python/Site_P3/psycopg2-2.4.5-py2.7-macosx-10.7-x86_64.egg/psycopg2/

(It's been a few years since I've written any Python, so I'm a bit groggy on the package installation
procedures, but it's all slowly coming back)


psycopg by date

Next:From: Daniele VarrazzoDate: 2012-03-31 23:32:28
Subject: Re: Using with Python 3, possible? how?
Previous:From: Daniele VarrazzoDate: 2012-03-31 17:20:48
Subject: Re: dll load fail

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