mvantellingen/psycopg2-ctypes — Issue #21: can't import psycopg2 on windows
Author: eire1130
Created: 2012-02-19 17:27:24+00:00
State: open

The setup.py takes a few modifications to get working. However, once installed you can't import psycopg2. You end up with the following error:

I forked the project and made the appropriate edits to setup.py to find libpq.dll. If you like, I can push this small change.

This traceback is from pypy (which is what i want to get working)

>>>> import psycopg2
Traceback (most recent call last):
File "", line 1, in
File "C:\pypy-1.8\site-packages\psycopg2.py", line 7, in
from psycopg2ct import compat
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\__init__.py", line 4, in
from psycopg2ct import extensions
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\extensions.py", line 15, in
from psycopg2ct._impl import connection as _connection
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\connection.py", line 8, in
from psycopg2ct._impl import libpq
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\libpq.py", line 9, in
libpq = cdll.LoadLibrary(PG_LIBRARY)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 433, in Lo
adLibrary
return self._dlltype(name)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 354, in __
init__
self._handle = _ffi.CDLL(name, mode)
OSError: C:/Program Files (x86)/PostgreSQL/9.1/lib/libpq.dll: The specified modu
le could not be found.
>>>>

You also end up with a popup that says: "Python.exe - System Error"

The Program can't start because libintl-8.dll is missing from your computer. Try reinstalling the program to fix this problem."

I have the odbc driver's installed and this dll is located at: C:\Program Files (x86)\PostgreSQL\psqlODBC\0900\bin

The error also shows up in standard python27:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\James>pypy
Python 2.7.2 (0e28b379d8b3, Feb 09 2012, 18:31:47)
[PyPy 1.8.0 with MSC v.1500 32 bit] on win32
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``PyPy development: the art of
waiting''
>>>> import psycopg2
Traceback (most recent call last):
File "", line 1, in
File "C:\pypy-1.8\site-packages\psycopg2.py", line 7, in
from psycopg2ct import compat
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\__init__.py", line 4, in
from psycopg2ct import extensions
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\extensions.py", line 15, in
from psycopg2ct._impl import connection as _connection
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\connection.py", line 8, in
from psycopg2ct._impl import libpq
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\libpq.py", line 9, in
libpq = cdll.LoadLibrary(PG_LIBRARY)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 433, in Lo
adLibrary
return self._dlltype(name)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 354, in __
init__
self._handle = _ffi.CDLL(name, mode)
OSError: C:/Program Files (x86)/PostgreSQL/9.1/lib/libpq.dll: The specified modu
le could not be found.
>>>> import psycopg2
Traceback (most recent call last):
File "", line 1, in
File "C:\pypy-1.8\site-packages\psycopg2.py", line 7, in
from psycopg2ct import compat
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\__init__.py", line 4, in
from psycopg2ct import extensions
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\extensions.py", line 15, in
from psycopg2ct._impl import connection as _connection
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\connection.py", line 8, in
from psycopg2ct._impl import libpq
File "C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg2ct
\_impl\libpq.py", line 9, in
libpq = cdll.LoadLibrary(PG_LIBRARY)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 433, in Lo
adLibrary
return self._dlltype(name)
File "C:\pypy-1.8\lib-python\modified-2.7\ctypes\__init__.py", line 354, in __
init__
self._handle = _ffi.CDLL(name, mode)
OSError: C:/Program Files (x86)/PostgreSQL/9.1/lib/libpq.dll: The specified modu
le could not be found.
>>>> ^C
C:\Users\James>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg
2ct
File "", line 1
import C:\pypy-1.8\site-packages\psycopg2ct-2.4.4._ctypes_-py2.7.egg\psycopg
2ct
^
SyntaxError: invalid syntax
>>> import psycopg2ct
Traceback (most recent call last):
File "", line 1, in
File "build\bdist.win32\egg\psycopg2ct\__init__.py", line 4, in
File "build\bdist.win32\egg\psycopg2ct\extensions.py", line 15, in
File "build\bdist.win32\egg\psycopg2ct\_impl\connection.py", line 8, in
File "build\bdist.win32\egg\psycopg2ct\_impl\libpq.py", line 9, in
File "c:\python27\lib\ctypes\__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "c:\python27\lib\ctypes\__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
>>>