I need to have GDAL/OGR working with Python 3.2 because of another dependency. However, I also want to have QGIS for convenience. However, QGIS - FWTools in particular is built against Python 2.5, so while most of QGIS works, I have none of the FWTools raster tools.
The error message I get is:
Couldn't load plugin GdalTools due an error when calling its classFactory() method
Traceback (most recent call last): File "C:/OSGeo4W/apps/qgis/./python\qgis\utils.py", line 138, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/OSGeo4W/apps/qgis/./python/plugins\GdalTools__init__.py", line 32, in classFactory from GdalTools import GdalTools File "C:/OSGeo4W/apps/qgis/./python\qgis\utils.py", line 283, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/OSGeo4W/apps/qgis/./python/plugins\GdalTools\GdalTools.py", line 39, in raise ImportError( error_str ) ImportError: Module use of python32.dll conflicts with this version of Python.
Python version: 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
I have tried using the QGIS Windows installer and the OSGeo4W installer and have Python 2.5 under the OsGeo4W folder. Is there an easy way of having the FWTools working correctly in QGIS and have GDAL/OGR working with Python 3.2?
In your answers you need to bear in mind that I am not familiar with compiling from source (sorry), but willing to learn if that is required and somebody can hold my hand through the process.
Thanks
Answer
I had been putting off sorting this problem out for a long time but finally have a proper solution. The situation is this:
- I need a 64bit version of Python 32 and GDAL for a package other than QGIS.
- I need a 32bit version of GDAL to work with Python 2.7 for QGIS.
- QGIS consistently loads the wrong DLL and complains that it is not a 32bit Windows application.
The reason and solution are simple. I have environment variables which point to the 64 bit GDAL installation - which was installed before QGIS and I need to leave alone so my other applications will work. OSGeo appends its path information to the system path but because it is put at the end of the path, my pre-existing installs for 64-bit Python 3.2 are always picked up. So, I added the following code at the start of the GdalTools.py file (I used the one in C:\Users\MyAccount.qgis\python\plugins\GdalTools):
# hack the path to force QGIS to look in OSGeo4w directory first
import sys
sys.path.reverse()
Now QGIS starts with zero errors and I can use the GDAL tools, without switching to another machine.
EDIT (Windows 64 bit version July 2014): I STILL have to do this hack because QGIS still uses Python27 and I need Python32 for other packages I use. I still get the same error message and forcing the paths in config section for QGIS still doesn't solve entirely the problem. However, this hack continues to neatly cure the issue (I am now editing the version of gdaltools.py in C:\OSGeo4W64\apps\qgis\python\plugins\GdalTools
on my system.
No comments:
Post a Comment