Reputation: 1473
I used the article on https://github.com/nwcell/psycopg2-windows and https://bitbucket.org/topper/psycopg2-win64-py27/overview to get psycopg2 installed and working on Python2.7 and Cygwin.
The install ran fine and i see the package in the /usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/ directory.
However the import does not work.. Any idea on this error?
Python 2.7.8 (default, Jul 25 2014, 14:04:36)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named _psycopg
Thanks, Manish
Upvotes: 3
Views: 1727
Reputation: 1
You must use Cygwin package installer
to install BOTH of the two packages:
libecpg6
, for psycopg2
runtime library support, without it you will get
'ImportError: No module named _psycopg' when you run your script.
libecpg-devel
, for compiling psycopg2
without it you will get a lot of
such as pthread_***
errors when you install psycopg2 using pip tool.As time goes on, those package name may be changed, but you should know what's you deficiency.
Upvotes: 0
Reputation: 2263
It's mandatory to install libpq
, which sometimes is not installed as part of libpq-devel
. As of now, I succedded installing libpq5
.
Upvotes: 1
Reputation: 1
Env = python 2.7.10 (cygwin distribution), Windows 7, Cygwin 64
1) pip install psycopg2 failed as I didn't have pip debug
2) Installed pip from here: pip.pypa.io/en/stable/installing/
3) pip install psycopg2 failed due to 'no pg_config...'
4) psycopg2 installer for win (www.stickpeople.com/projects/python/win-psycopg/) failed cause I am using cygwin's python install, not the python in the machine's registry and this installer won't allow user to install anywhere else other thatn the python that is registred with Windows (Installer succeeded, but the files were not where I needd them.) ("Copying" the files didn't work.)
5) This (https://github.com/nwcell/psycopg2-windows) pip install "worked" (gave no errors) but when I tried to import, I got the message: "ImportError: No module named psycopg2"
6) pip uninstall psycopg2
7) Tried to pip install libpq-dev and python-dev "Could not find a version that satisfies the requirement libpq-dev (from versions: ) No matching distribution found for libpq-dev"
8) installed Postgres & pg_config from here http://www.enterprisedb.com/products-services-training/pgdownload#windows
9) added pg_config to path
10) pip install psycopg2 now worked
11) import psycopg2 in .py file caused core dump
Stack trace: Frame Function Args 006001A5A60 0018007261A (000FFFFE3F4, 0000000E514, 00000000000, 000FFFFDE50) 006001A5B00 00180073DD0 (00077801FD6, 00000000000, 00000000140, 00000000000) 006001A5D50 0018012EF8F (00600010540, 00000000000, 003DB05FDB0, 6FFFFF28050) 006001A6040 0018012BC70 (0000000000D, 00000000000, 00000000000, 0018013D7DA) 00000000000 0018012C139 (006001A6030, 3630303030303030, 3036303030303030, 00000 00000B) 00000000000 0018012C30C (00000000000, 10000000A8E73, 6F007000650072, 61006C0074 0072) 00000000000 00180127BFB (00000000000, 10000000A8E73, 6F007000650072, 61006C0074 0072) 00000000000 00180071169 (01000000010, 00000000000, 00000000000, 000FFFFCE00) 000FFFFAA00 00180073D11 (B64000B00630079, 00000000088, 1D17578E1C375D4, 1D17578 E16661AE) 52004F00520052 64006F00630072 (00000000088, 1D17578E1C375D4, 1D17578E16661AE, 1 D175A09055FB4F) 52004F00520052 70002E00730065 (1D17578E1C375D4, 1D17578E16661AE, 1D175A09055FB4 F, 1D175A09055FB4F) 52004F00520052 B64000B00630079 (1D17578E16661AE, 1D175A09055FB4F, 1D175A09055FB 4F, 0000000180B) 52004F00520052 00000000088 (1D175A09055FB4F, 1D175A09055FB4F, 0000000180B, 0000 0002000) 52004F00520052 1D17578E1C375D4 (1D175A09055FB4F, 0000000180B, 00000002000, 01A0 0000020) 52004F00520052 1D17578E16661AE (0000000180B, 00000002000, 01A00000020, 45001600 000000) 52004F00520052 1D175A09055FB4F (00000002000, 01A00000020, 45001600000000, 4E004 500540058) End of stack trace (more stack frames may be present)
(The above took ~2 days.)
12) pip install pg8000 worked
13) imported pg8000 to .py file and connected to DB (Steps 12 and 13 took ~20 minutes.)
Upvotes: 0
Reputation: 1858
I was getting this exact set of messages -- but not in my local Cygwin/Babun dev environment -- I got them when I pushed to the RHEL 7 server to test there. It took two days to flush it out, and how I solved it likely doesn't apply to you. But I learned some things that probably do.
Another cause of this error is argued at great length in these bug reports (with Python and psycopg pointing fingers at each other) -- and generally not worth the read -- read on below instead:
The gist of it? Look for some updates -- it looks like they both might have made some small changes that affect this.
Anyway... this is how I installed psycopg2 in Cygwin (assuming Babun's pact installer is available):
pact install libpq-devel
pip install psycopg2
Yup, that's it! (Some envs might also require a C compiler and python*-devel.)
An alternative to installing libpq-devel is to install Windows Postgres and add the location of its pg_config
file to your PATH so that pip can compile psycopg2 -- but installing libpq-devel from the Cygwin shell is cleaner and it puts its pg_config
where pip can already find it.
I installed pyscopg2 from within a virtual env but that shouldn't have mattered. What might matter, however, could be one of the following:
sys.path
values from within Python to make sure it looks as you would expect. This doesn't appear to be your problem according to what you posted, but I mention it because this was ultimately my problem on RHEL 7 and how Apache was loading the virtual envs. ---- (Just another note here: I ultimately resolved the RHEL problem by compiling another mod_wsgi for Python 3.4.3, as per their instructions, to match my virtual envs. The previous mod_wsgi was running under Python 2.7.5 and that version was failing to import _psycopg
from a C library. Besides, I didn't want 2.7 running at all.)Upvotes: 1