2

I'm a Windows user getting an error when using GDAL from the command line (which I'd like to do for a couple reasons).

Attempting to use gdal_polygonize.py (in my case), as in:

gdal_polygonize.py test\test-gdal-tmp.tif -f "ESRI Shapefile" test\test.shp test

results in the error:

from osgeo import gdal
ImportError: No module named osgeo

whereas the line "from osgeo import gdal" works fine if I just load up Python (e.g. some standard IDE).

Prompting the code to print out sys.path both in my IDE & from the GDAL command line actually results in a different set of paths. The IDE gives me the necessary & expected folders like C:\\Python27\\lib\\site-packages. The command line GDAL call actually gives me ARCGIS-related folders not in the IDE's path, e.g. C:\\Python27\\ArcGIS10.4\\lib\\site-packages & without the necessary path to find osgeo (obviously).

I'm sure I've done something sinful in installing GDAL &/or have some installation incompatibilities, but for the life of me I can't figure out what. How can I get command line GDAL not to change the system path?

Other info:

  • OS = Windows 10

  • To install GDAL, I grabbed the files from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal (GDAL‑2.1.3‑cp27‑cp27m‑win32.whl) and used pip

  • Have ArcGIS on my system (clearly)

  • Made some other attempts to install GDAL (e.g. with Anaconda) before realizing this wouldn't allow them to be integrated with other code as necessary for my project

  • Ultimately trying to get this code to work, hence the command lines: https://github.com/nypl-spacetime/map-vectorizer

1 Answer 1

1

Answered my own question with more Googling. See this blog post. Changing the registry as suggested by the author fixed it (i.e. regedit).

ARCGIS installs its own version of Python and sets up Windows to use that one instead... http://blog.rtwilson.com/how-to-set-the-python-executable-used-to-run-py-files-from-the-command-line-on-windows/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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