Author chba
Recipients Arfrever, Trundle, barry, brett.cannon, chba, eric.smith, eric.snow, jcea, jkloth, lemburg, loewis, meador.inge
Date 2014-03-25.18:12:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395771141.46.0.648255360887.issue16047@psf.upfronthosting.co.za>
In-reply-to
Content
$ cat hello.py
import _psycopg
print('Works.')
$ export PYTHONVERBOSE=2
$ ./hello 2> res.txt
$ cat res.txt | grep psycopg           
# trying /export/scratch/chris/pgtest/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /export/scratch/chris/pgtest/_psycopg.cpython-34m.so
# trying /export/scratch/chris/pgtest/_psycopg.abi3.so
# trying /export/scratch/chris/pgtest/_psycopg.so
# trying /export/scratch/chris/pgtest/_psycopg.py
# trying /export/scratch/chris/pgtest/_psycopg.pyc
# trying /usr/lib/python3.4/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /usr/lib/python3.4/_psycopg.cpython-34m.so
# trying /usr/lib/python3.4/_psycopg.abi3.so
# trying /usr/lib/python3.4/_psycopg.so
# trying /usr/lib/python3.4/_psycopg.py
# trying /usr/lib/python3.4/_psycopg.pyc
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.cpython-34m.so
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.abi3.so
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.so
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.py
# trying /usr/lib/python3.4/plat-x86_64-linux-gnu/_psycopg.pyc
# trying /usr/lib/python3.4/lib-dynload/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /usr/lib/python3.4/lib-dynload/_psycopg.cpython-34m.so
# trying /usr/lib/python3.4/lib-dynload/_psycopg.abi3.so
# trying /usr/lib/python3.4/lib-dynload/_psycopg.so
# trying /usr/lib/python3.4/lib-dynload/_psycopg.py
# trying /usr/lib/python3.4/lib-dynload/_psycopg.pyc
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.cpython-34m.so
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.abi3.so
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.so
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.py
# trying /usr/local/lib/python3.4/dist-packages/_psycopg.pyc
# trying /usr/lib/python3/dist-packages/_psycopg.cpython-34m-x86_64-linux-gnu.so
# trying /usr/lib/python3/dist-packages/_psycopg.cpython-34m.so
# trying /usr/lib/python3/dist-packages/_psycopg.abi3.so
# trying /usr/lib/python3/dist-packages/_psycopg.so
# trying /usr/lib/python3/dist-packages/_psycopg.py
# trying /usr/lib/python3/dist-packages/_psycopg.pyc
    import _psycopg
ImportError: No module named '_psycopg'

----

$ cat hello.py
import _psycopg
print('Works.')
$ export PYTHONPATH=/usr/lib/python3/dist-packages/psycopg2:$PYTHONPATH
$ ./hello
Works.

----

The correct import (see the doc of psycopg2) is import psycopg2. Otherwise a valid script does even not run in interpreted mode. The library lies in /usr/lib/python3/dist-packages/psycopg2/_psycopg.cpython...so Maybe there is the Problem. One has to Import the parent dir of the so-file, which Triggers the bug.

$ cat hello.py
import psycopg2
print('Works.')
$ export PYTHONVERBOSE=2
$ ./hello 2> res.txt
$ cat res.txt | grep psycopg           
    import psycopg2
  File "/usr/lib/python3/dist-packages/psycopg2/__init__.py", line 67, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named 'psycopg2._psycopg'
# destroy psycopg2


Marc-Andre: would you mind to install python3-psycopg2 to see that in real?
History
Date User Action Args
2014-03-25 18:12:21chbasetrecipients: + chba, lemburg, loewis, barry, brett.cannon, jcea, eric.smith, jkloth, Arfrever, Trundle, meador.inge, eric.snow
2014-03-25 18:12:21chbasetmessageid: <1395771141.46.0.648255360887.issue16047@psf.upfronthosting.co.za>
2014-03-25 18:12:21chbalinkissue16047 messages
2014-03-25 18:12:21chbacreate