1

I just used home-brew to update my version of GDAL. I was using GDAL version 1.11, which could not read .grd files.

import gdal
import matplotlib.pyplot as plt
from colormap import Colormap

quant = gdal.Open('.../pct1/pct1.grd')

ERROR 4: `/Users/Nate/Documents/CSU/DroughtNet/WebApps/WorldClim_ShinyApp/data/pct1/pct1.grd' not recognised as a supported file format.

I used Homebrew to update my GDAL version to 1.9 to see if that fixes the problem, and GDAL did install successfully. However, I can't get Python to import the appropriate GDAL version, it still imports version 1.11.

I've tried editing the sys.path file, putting the current GDAL framework up front, but that didn't do it. The Homebrew install said to run

mkdir -p /Users/Nate/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/Nate/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Which I did, but that didn't work either. Probably because my Python is not run from /Users/Nate/Library/Python/ but comes from a different place. Any suggestions on how to get Python to recognize the newest GDAL version?

UPDATE

Per Matthew's comment, I was able to get the correct version of GDAL (1.9) to load. However, it still won't read my .grd file. Is there an extension that I need to add in order to read these files?

Nate
  • 1,888
  • 3
  • 18
  • 26

1 Answers1

0

This sounds like a job for a virtual environment. I would create an isolated environment (using virtualenv) from the one you mentioned and try to import GDAL using that Python environment. That way, it will have a fresh path and you can play around with importing it.

If you don't want to use a virtual environment, you should double-check to ensure that you are importing the correct GDAL version. Your script may be importing the old one if 1.9 was written in a separate place, rather than overwriting 1.11

As for debugging steps:

  1. Try printing out the Python path every time you run the script
  2. Print out the version of GDAL each run
  3. Try fiddling around with the inspect module (documentation) and see where exactly you are importing GDAL from and see if you can determine anything from there
Matthew R.
  • 438
  • 4
  • 11
  • My GDAL install is in /Library/Frameworks/GDAL.framework/Versions/, and each version has a different folder, 1.10, 1.11, 1.9. When I run import gdal, gdal.__file__, it comes from /Library/Frameworks/GDAL.framework/Versions/1.11/Python/2.7/site-packages. – Nate Jun 27 '15 at 15:28
  • When I run import gdal, gdal.__file__, it came from /Library/Frameworks/GDAL.framework/Versions/1.11/Python/2.7/site-packages. I checked my sys.path, and the third folder in sys.path is that same folder. I modified my sitecustomize.py file to insert the 1.9 folder in from of this on startup and that worked. Thanks! As an aside, do you know of a way to permanently modify the sys.path so I can delete the 1.11 path? – Nate Jun 27 '15 at 15:37
  • I believe you would have to set your system's environment variable. On windows, you could use the "set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib" command in cmd.exe ([SO answer here])(http://stackoverflow.com/a/3701730/3748574) or do it via the Windows GUI with [these instructions](https://stackoverflow.com/questions/25153802/how-to-set-python-path-in-windows-7) – Matthew R. Jun 27 '15 at 20:01