Several Python packages are best installed with a Windows installer. But those installers install to the system-wide Python directory. How do I set the Python path in QGIS?

I tried setting PYTHONPATH as a Windows environment variable. It can import netCDF4 (which is installed globally), but the import doesn't succeed because it cannot load a DLL. So perhaps also some DLL load path needs to be adjusted?

  • 1
    What other Python versions do you have installed? QGIS ships with Python 2.5. It could be that that your netCDF4 Python bindings are for a newer version of Python. Could you post the error message? – R.K. Feb 23 '12 at 16:14

You can come at it from the opposite direction and make the Qgis python a system python, which enables using standard Windows installers for the extra packages.

This can be done by creating or modifying the windows registry. Here's an example for python 2.7 distributed with Osgeo4w, installed in a non-standard location:

Windows Registry Editor Version 5.00

I created an experimental o4w register python package to add and remove this registry setting at will. It's not o4w or python version specific and uses the currently active environment to determine the appropriate version number and path values. The code is here and works best on 32bit systems; there are some peculiarities to 64bit registries I haven't figured out how to deal with yet.

register-python does nothing if the system python is the same major version, e.g. you can only have one Python 2.6 at a time. It is perfectly workable to have ArcGIS 10 python 2.6 in the registry at the same time as Qgis python 2.7 though.

If you're using the manual approach and editing the registry directly, you can save the current system python by simply renaming it, running the install programs, and then changing it back. Example:

; rename to:
  • 1
    How would I do this on Mac/Linux? – gregmacfarlane Feb 14 '13 at 14:54
  • @gmacfarlane I've no idea. It's worth asking as a separate question as the Mac answer will be very different. – matt wilkie Feb 14 '13 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.