psycopg2 Import Error with Cygwin Python

For quite a while I struggled with mysterious import error when trying to use psycopg2 (2.0.7) from Cygwin Python. The actual import error varied depending on how I installed psycopg. Here’s one error:

Traceback (most recent call last):
  File "foo.py", line 1, in 
    import psycopg2
  File "build/bdist.cygwin-1.5.25-i686/egg/psycopg2/__init__.py", line 60, in 
  File "build/bdist.cygwin-1.5.25-i686/egg/psycopg2/_psycopg.py", line 7, in 
  File "build/bdist.cygwin-1.5.25-i686/egg/psycopg2/_psycopg.py", line 6, in __bootstrap__
ImportError: No such file or directory

There is no _psycopg.py file, it is really _psycopg.dll.

When you try to build psycopg2, you will run into build errors that lead you into installing postgresql-devel and libpgtypes2 Cygwin packages. Unfortunately while this is enough to build psycopg2, the import still fails. The solution is to also install libpq4 Cygwin package.

Similar Posts: