Re: how to compile psycopg2 on windows?

From: Jason Erickson <jerickso(at)stickpeople(dot)com>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: Bright Pan <loststriker(at)gmail(dot)com>, psycopg(at)postgresql(dot)org
Subject: Re: how to compile psycopg2 on windows?
Date: 2011-01-09 19:10:55
Message-ID: 20110109104116.R39273@stickpeople.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Sun, 9 Jan 2011, Daniele Varrazzo wrote:

> On Sun, Jan 9, 2011 at 7:45 AM, Bright Pan <loststriker(at)gmail(dot)com> wrote:
>> i compiled pscopg2 2.3.2 and install successful, but the error is happen:
>> ImportError: DLL load failed.
>> i find the file_psycopg.pyd is only 127KB, but official package on windows
>> is 1MB.
>> the following is my compiling step:
>> python setup.py build_ext -c mingw32install
>
> Probably you have built a library dynamically linked to the libpq,
> whereas the Jason packages have the libpq statically linked. The
> setting can be configured using the static_libpq setting in the
> setup.cfg.
>
> This of course doesn't solve all the issues of the Windows build. I
> know Jason is polishing the build system he uses for his packages,
> which is not a trivial one as he also builds the libpq and the ssl
> libs together with psycopg. I hope good news should come from him,
> also about the issue #20 :)

I believe Daniele is directing you in the right direction. The package I
build is statically linked to both libpq and openssl, resulting in the 1MB
size. In the past when I've only linked to libpq, the size is around
500KB, just to give you an idea. Based upon your size, I would think that
it is linking to import library pointing to the libpq.dll.

You did not mention how you got the PostgreSQL 'code' (Standard
download/installation, compiling by self). Looking at the 9.0 prebuilt
binaries, the libpq.lib points to the libpq.dll. To confuse you even more,
if you build the code yourself, the names differs as follows:
libpq.lib 400KB --> static libpq library (not libpq.dll)
libpqdll.lib 32KB --> loads libpq.dll

Hmm, so short answer is that depending on how you get the binaries
partially determines static/dynamic linkage. So the 'static_libpq'
setting mentioned previously might not do what it says. Arrrrg.

As a test, you could place the libpq.dll into \windows\system32 and see if
you still get the error (There is a more pythonic location to place it,
too, at %PYTHONDIR%\Lib\site-packages\psycopg2). If libpq.dll is already
in system32, it could be an older version causing problems. If placing it
in system32 works, you can then move it to a more pythonic location.

-jason

>
> What Python version are you using anyway? I remember building with up
> to Python 2.5 was an easy task using this bundle [1], but with Python
> 2.6 I found problems, maybe related to the issue #3308 [2]
>
> [1] http://www.develer.com/oss/GccWinBinaries
> [2] http://bugs.python.org/issue3308
>
> -- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Jason Erickson 2011-01-09 19:48:23 psycopg2 w/apache on win32 (Issue #20)
Previous Message Daniele Varrazzo 2011-01-09 12:52:29 Re: how to compile psycopg2 on windows?