Backup of David's Livejournal

How to install PyGreSQL (Python's PostgreSQL module)


Installing PyGreSQL isn't trivial, especially on Dell computers.  Here's a recipe that worked for me and Python 2.5:

  1. Download and install postgresql-8.3.5-2-windows.exe  (You shouldn't need the whole install.)
  2. Add C:\Program Files\PostgreSQL\8.3\lib to your PATH for libpq.dll.
  3. Add C:\Program Files\PostgreSQL\8.3\bin to your PATH for ssleay32.dll.
  4. Hide System32's copy of LIBEAY32.dll  (If you're on a DELL, and that one is far smaller and older than the others.)
  5. Download and install PyGreSQL-4.0.win32-py2.5.exe
And here's some explanation with accompanying error text so that people searching for a solution to this problem can find it.  Here's my experience:

Downloaded PyGreSQL first, before realizing it had dependencies to a postgresql install.  Got some nebulous ImportErrors when I tried to "import pg".

from _pg import *
ImportError: DLL load failed: The specified module could not be found.
Great.  What module?  Searching the web, I discovered I needed to install postgresql.  So I did, but I still got the error, even after updating the system's PATH variable.  (Note, sys.path and os.environ("PATH") are two different things.)  Eventually I discovered this great tip:

Try doing the failing import from the Python command line.  (Start->Python 2.5->Python (command line)).  Doing that will actually display a modal dialog that says exactly which dll could not be loaded.  Yay!

Finally, I got the LIBEAY32.dll error mentioned above, the exact text of which follows:

The ordinal 2821 could not be located in the dynamic link library LIBEAY32.dll
and once I hid the old LIBEAY32.dll, I got pg linking with the correct libraries, I was good to go.  Hope this helps somebody.

Comments

 tpederson on Jan 21st 2009 at 11:50 PM
I just finished some dev work, but I used sqlite on my local machine, and as an added bonus found and used the SQLite manager extension in FireFox. Mercifully, when it came time to move to the production server, our I.T. guy installed postgres. It's a linux/apache/Django setup, so the python db module was 'postgresql_psycopg2', so it was a different beast, but from what I understand it wasn't trivial either.

 (no name) on Jan 29th 2009 at 5:35 AM
I just got the first error you describe...what a disappointing mess!

 (no name) on Mar 24th 2009 at 5:15 PM
and I won! Finally, after renaming the libeay32.dll file as you suggested. Damn what a PIA. Dan

 (no name) on Nov 14th 2009 at 6:48 PM
Great, thanks. This really helped me. I have a Dell Desktop though and didn't have to hide the LIBEAY32.dll. Just adding the PostgreSQL BIN and LIB sub-dirs to my environment variable PATH worked.

 bothwill on Oct 21st 2010 at 6:14 PM
I get the same error every time I try to install the software. I should tell that I am not using a Dell, are these steps actually specific just for Dell computers? I even searched for more information on Microsoft dll files and I think I found a valuable track there. Is there any other resource you could share on this topic?