[Qgis-user] qgis 1.8: import error with psycopg2._psycopg (windows)

Max Bohnet max.bohnet at tu-harburg.de
Wed Jul 11 13:48:44 PDT 2012


Today I installed QuantumGIS 1.8 with the osgeo4w-installer - including 
python and psycopg2.
Quantum 1.8 works, but many plugins cannot be used because psycopg2 
cannot be imported:
When i use the python console in QGIS (or a python console with the 
python 2.7 that was installed in C:\osgeo4w\bin) the following error 
occures:

> >>> import psycopg2
>
> Traceback (most recent call last):
>
> File "<input>", line 1, in <module>
>
> File "C:/osgeo4w/apps/qgis/./python\qgis\utils.py", line 309, in _import
>
> mod = _builtin_import(name, globals, locals, fromlist, level)
>
> File 
> "C:\osgeo4w\apps\Python27\lib\site-packages\psycopg2\__init__.py", 
> line 71, in <module>
>
> from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
>
> File "C:/osgeo4w/apps/qgis/./python\qgis\utils.py", line 309, in _import
>
> mod = _builtin_import(name, globals, locals, fromlist, level)
>
> ImportError: DLL load failed: Das Betriebssystem kann %1 nicht ausführen.
>
> >>>
>

The error is also described in :
http://stackoverflow.com/questions/1306367/importerror-dll-load-failed-when-trying-to-import-psycopg2-library

I have a computer with windows 7 64bit with 32bit python (2.6, 2.7) 
installed.

I have another Python27 installed in C:\Python27
psycopg2 is working there without any problems.

i tried to install another version of psycopg2 (2.3 from osgeo....) but 
with the same error.

  - however i did not manage to use the windows installer (it installs 
psycopg2 always in the "normal" python folder - not in the python in 
osgeo4w).
http://www.stickpeople.com/projects/python/win-psycopg/psycopg2-2.4.5.win32-py2.7-pg9.1.3-release.exe
I tried to change the registry entry for python to redirect it to 
c:\osgeo4w\python27 . But the installation fails.

When i try to install psycopg2 form the source (with easy-install oder 
C:\osgeo4w\bin\python.exe setup.py install) the following error 
occures,when  building the _psycopg file:
> C:\osgeo4w\bin\psycopg2-2.4.5>C:\MinGW\bin\gcc.exe -mno-cygwin -mdll 
> -O -Wall -DPSYCOPG_DEFAULT_PYDATETIME=1 "-DPSYCOPG_VERSION=\"2.4.5 (dt 
> dec pq3 ext)\"" -DPG_VERSION_HEX=0x090005 -DPSYCOPG_EXTENSIONS=1 
> -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFR
> EEMEM=1 -IC:\Python27\include-IC:\Python27\PC -I. 
> -IC:/PROGRA~2/POSTGR~1/9.0/include 
> -IC:/PROGRA~2/POSTGR~1/9.0/include/server -c psycopg\psycopgmodule.c 
> -o build\temp.win32-2.7\Release\psycopg\psycopgmodule.o -O3 
> -fno-strict-aliasing
cc1.exe: error: unrecognized command line option '-mno-cygwin'

i tried to remove the occurence of -mno-cygwin in
C:\osgeo4w\apps\python27\Lib\distutils\cygwinccompiler.py
as described in
http://stackoverflow.com/questions/9645004/python-mno-cygwin
but that does not help.
If i try to execute the command without -mno-cygwin

C:\osgeo4w\bin\psycopg2-2.4.5>C:\MinGW\bin\gcc.exe -mdll -O -Wall 
-DPSYCOPG_DEFAULT_PYDATETIME=1 "-DPSYCOPG_VERSION=\"2.4.5 (dt dec pq3 
ext)\"" -DPG_VERSION_HEX=0x090005 -DPSYCOPG_EXTENSIONS=1 
-DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFR
EEMEM=1 -IC:\Python27\include-IC:\Python27\PC -I. 
-IC:/PROGRA~2/POSTGR~1/9.0/include 
-IC:/PROGRA~2/POSTGR~1/9.0/include/server -c psycopg\psycopgmodule.c -o 
build\temp.win32-2.7\Release\psycopg\psycopgmodule.o -O3 
-fno-strict-aliasing

he complains because of a missing python.h file.

I tried to reinstall the osgeo4w-python-core and psycopg2, but the 
problem is still there.

Has anyone an idea, what other solutions i could try?
Is there a possibility to use my "normal" python2.7 installation on 
c:\python27 for QuantumGIS?

Thanks in advance for any help,

Max



More information about the Qgis-user mailing list