ImportError: Permission denied when importing psycopg2 module

I'm trying to setup an Python application which uses PostgreSQL through psycopg2, but the module keeps failing when importing it.

ImportError: Permission denied

I've installed psycopg2 using pip both globally and in a virtualenv

The environment is the following: (Cygwin on XP x86)

Python 2.6.8 (unknown, Jun  9 2012, 11:30:32)
[GCC 4.5.3] on cygwin

Importing the module:

[12:49:45] /usr/lib/python2.6/site-packages/psycopg2 $ python -c "import psycopg2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/psycopg2/__init__.py", line 67, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: Permission denied

The problematic module is _psycopg, the _psycopg.dll, if I rename it, the module cannot be found, as expected.

[12:50:01] /usr/lib/python2.6/site-packages/psycopg2 $ mv _psycopg.dll X_psycopg.dll
[13:00:53] /usr/lib/python2.6/site-packages/psycopg2 $ python -c "import psycopg2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/psycopg2/__init__.py", line 67, in <module>
    from psycopg2._psycopg import BINARY,
ImportError: No module named _psycopg

File permissions:

-rwxr-xr-x 1 L0009813 Ninguno 739979 jul 16 12:11 _psycopg.dll

User information:

[13:01:40] /usr/lib/python2.6/site-packages/psycopg2 $ id
  uid=1008(L0009813) gid=513(Ninguno) grupos=513(Ninguno),0(root),544(Administradores),545(Usuarios)

I have PostgreSQL correctly installed (9.1), I've tried the pgAdmin and managed to create and access a database, but I think the problem occurs before trying to connect to PGSQL.

I can move, delete, etc the DLL file, and AFAIK, no other users are involved in the operation, I've searched and tried everything I've found, but I'm unable to find a solution, it's very frustrating because I'm sure I'm missing a small detail int he process.

Answers


Installing with pip is known to set the umask very restrictive. Try running:

sudo chmod -R a+rX /usr/lib/python2.6/site-packages

(Mind the capital X; it will only apply the execute permissions to directories.)


Need Your Help