Re: psycopg2 and python built with ucs2

From: Scott Rohde <srohde(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Re: psycopg2 and python built with ucs2
Date: 2011-09-06 23:10:21
Message-ID: CAEPRSL-kf2v=xEESFWutxtYSron=V8erXJDHNXx_rz81XXU5wg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Thought I'd reply to myself. Better late than never.

The answer is yes, there is a simple way to get psycopg to work with
python built with ucs2.

If you're seeing the following error:
ImportError: /usr/local/lib/python2.4/site-packages/psycopg2/_psycopg.so:
undefined symbol: PyUnicodeUCS4_Decode

You have two choices:
1. recompile python with ucs4 OR,
2. recompile psycopg2 with a python that was built with ucs2

As far as I can tell, psycopg2 makes no assumption on the unicode
width - it will work with whatever python it's compiled with.

For 1., pass '--enable-unicode=ucs4' to python's configure script and
build python

For 2., run the setup.py script with a ucs2 python (i.e.
`python-built-with-ucs2 setup.py build`)

pythons unicode C api was designed as follows (from unicodeobject.h):

/* --- UCS-2/UCS-4 Name Mangling ------------------------------------------ */

/* Unicode API names are mangled to assure that UCS-2 and UCS-4 builds
produce different external names and thus cause import errors in
case Python interpreters and extensions with mixed compiled in
Unicode width assumptions are combined. */

#ifndef Py_UNICODE_WIDE
...
# define PyUnicode_Decode PyUnicodeUCS2_Decode
...
#else
...
# define PyUnicode_Decode PyUnicodeUCS4_Decode
...

Regards,
Scott

On Fri, Jul 29, 2011 at 10:01 AM, Scott Rohde <srohde(at)gmail(dot)com> wrote:
> Hello,
>
> When I import psycopg2 from python built with ucs2 I get the following error:
> ImportError: /usr/local/lib/python2.4/site-packages/psycopg2/_psycopg.so:
> undefined symbol: PyUnicodeUCS4_Decode
>
> By recompiling python to use ucs4 this error goes away and I can
> successfully use psycopg2.
>
> However, in my situation it would be much more convenient if I could
> get psycopg2 to work with python built with ucs2.  Is there a simple
> way to do that?
>
> Thanks very much,
>
> --
> -Scott
>

--
-Scott

In response to

Browse psycopg by date

  From Date Subject
Next Message Federico Di Gregorio 2011-09-07 09:12:13 Re: About pyvertica (a clone of pyscopg2)
Previous Message Daniele Varrazzo 2011-09-02 15:00:16 Re: psycopg2.extensions.adap