Search code examples
python-2.7cygwinpostgresql-9.2psycopg2

Cygwin 32 and Python 2.7.5: psycopg2 installation error


In my previous question I described our situation: our developers are to use python in a cygwin environment over windows 7 - 64 bit however the tests are automaticaly executed during build as well on linux. We experienced some trouble with cygwin64 so now we tried to use python over cygwin32.

Regrettably it seems that using both the 64 and 32 bit versions of PostgreSQL 9.2 makes a gcc compilation error during the installation of psycopg2. The 32 bit version install log:

$ pip install psycopg2

...

Downloading/unpacking psycopg2 Downloading psycopg2-2.5.1.tar.gz (684kB): 684kB downloaded Running setup.py egg_info for package psycopg2

Installing collected packages: psycopg2 Running setup.py install for psycopg2 building 'psycopg2._psycopg' extension gcc -fno-strict-aliasing -ggdb -O2 -pipe -fdebug-prefix-map=/home/jt/rel/python-2.7.3-1/python-2.7.3-1/build=/usr/src/debug/python-2.7.3-1 -fdebug-prefix-map=/home/jt/rel/python-2.7.3-1/python-2.7.3-1/src/Python-2.7.3=/usr/src/debug/python-2.7.3-1 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.5.1 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090204 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/usr/include/python2.7 -I. -IC:/PROGRA~2/POSTGR~1/9.2/include -IC:/PROGRA~2/POSTGR~1/9.2/include/server -c psycopg/psycopgmodule.c -o build/temp.cygwin-1.7.24-i686-2.7/psycopg/psycopgmodule.o

In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:307:8: error: redefinition of ‘struct timespec’
In file included from /usr/include/stdio.h:47:0,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/sys/types.h:130:8: note: originally defined here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:571:24: error: conflicting types for ‘pthread_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:178:45: note: previous declaration of ‘pthread_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:572:34: error: conflicting types for ‘pthread_attr_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:182:50: note: previous declaration of ‘pthread_attr_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:573:32: error: conflicting types for ‘pthread_once_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:193:1: note: previous declaration of ‘pthread_once_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:574:33: error: conflicting types for ‘pthread_key_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:181:49: note: previous declaration of ‘pthread_key_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:575:35: error: conflicting types for ‘pthread_mutex_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:179:51: note: previous declaration of ‘pthread_mutex_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:576:39: error: conflicting types for ‘pthread_mutexattr_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:183:55: note: previous declaration of ‘pthread_mutexattr_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:577:34: error: conflicting types for ‘pthread_cond_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:185:50: note: previous declaration of ‘pthread_cond_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:578:38: error: conflicting types for ‘pthread_condattr_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:184:54: note: previous declaration of ‘pthread_condattr_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:580:36: error: conflicting types for ‘pthread_rwlock_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:195:52: note: previous declaration of ‘pthread_rwlock_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:581:40: error: conflicting types for ‘pthread_rwlockattr_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:196:56: note: previous declaration of ‘pthread_rwlockattr_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:582:38: error: conflicting types for ‘pthread_spinlock_t’
In file included from /usr/include/sys/types.h:473:0,
                 from /usr/include/stdio.h:47,
                 from /usr/include/python2.7/Python.h:33,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/cygwin/types.h:194:54: note: previous declaration of ‘pthread_spinlock_t’ was here
In file included from ./psycopg/config.h:120:0,
                 from ./psycopg/psycopg.h:33,
                 from psycopg/psycopgmodule.c:27:
C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:1131:31: error: conflicting types for ‘pthread_kill’
In file included from /usr/include/signal.h:5:0,
                 from /usr/include/time.h:138,
                 from /usr/include/sys/select.h:24,
                 from /usr/include/cygwin/sys_time.h:13,
                 from /usr/include/sys/time.h:61,
                 from /usr/include/python2.7/pyport.h:319,
                 from /usr/include/python2.7/Python.h:58,
                 from ./psycopg/psycopg.h:30,
                 from psycopg/psycopgmodule.c:27:
/usr/include/sys/signal.h:170:5: note: previous declaration of ‘pthread_kill’ was here
error: command 'gcc' failed with exit status 1

...

C:/PROGRA~2/POSTGR~1/9.2/include/pthread.h:1131:31: error: conflicting types for ‘pthread_kill’

In file included from /usr/include/signal.h:5:0,

             from /usr/include/time.h:138,

             from /usr/include/sys/select.h:24,

             from /usr/include/cygwin/sys_time.h:13,

             from /usr/include/sys/time.h:61,

             from /usr/include/python2.7/pyport.h:319,

             from /usr/include/python2.7/Python.h:58,

             from ./psycopg/psycopg.h:30,

             from psycopg/psycopgmodule.c:27:

/usr/include/sys/signal.h:170:5: note: previous declaration of ‘pthread_kill’ was here error: command 'gcc' failed with exit status 1

...

We installed the standard Gcc and PostgreSQL libraries that come with the cygwin installation package. What to do next?

Thank you very much in advance: Joe, the public


Solution

  • The libpq bundled with the PostgreSQL installer was compiled with Microsoft Visual Studio as a native Windows binary.

    If linking to it from Cygwin happens to work, that's mostly luck. It's not a good idea. You really need to use libpq built for Cygwin with a Cygwin program.

    Frankly, I think you're much better off just working with native Windows these days and avoiding Cygwin entirely. You can use the mingw compiler with msys when you need a unix-like build system, and properly written Windows-compatible code deals with mixing mingw and msvc compiled binaries well.

    In your case I'd just install ActivePython or I'd install the stock Python build and then add psycopg2 myself.