1

I'm using Win10 (with the bash shell) and one of my python scripts requires gdal/osgeo.

I ended up trying multiple install methods (gdal was successful with all of them, but I couldn't use osgeo), but the last one was Anaconda.

But when I try and run the script, I get:

from osgeo import ogr
ImportError: No module named osgeo

And gdal info yields:

Usage: gdalinfo [--help-general] [-json] [-mm] [-stats] [-hist] [-nogcp] [-nomd]
                [-norat] [-noct] [-nofl] [-checksum] [-proj4]
                [-listmdd] [-mdd domain|`all`]*
                [-sd subdataset] [-oo NAME=VALUE]* datasetname

FAILURE: No datasource specified.

I did some digging and found that:

a) my GDAL folder doesn't have Python in it (I don't know if this is necessary, but some other questions I looked at seemed to specifically mention C:/GDAL/Python

Here's what the folder looks like, for your reference

b) in my C:/Python27/Lib/site-packages folder, I found an osgeo folder.

Here's what this looks like, for your reference

At risk of being terse: how do I make it work? (If this is a duplicate or there's a similar post that I missed, please link it)

2
  • 1
    try, conda install -c conda-forge gdal Commented Oct 19, 2018 at 15:37
  • +1 for conda-forge. And hopefully this is obvious, but make sure you activate the environment before running the script or you may be using a different install by accident.
    – mikewatt
    Commented Oct 19, 2018 at 19:27

1 Answer 1

2

Usually installing GDAL from OSGEO4W or NextGIS Installer, you need to use special command line shell. In this shell all needed path are set. And python interpreter must be started from this shell.

You must decide to use special shell or add text file with .pth extension to your python site-packages directory.

Note: site-packages directory must be belong to python interpreter you are starting!

In .pth file just write path to folder where osgeo directory located.

I'm developer at NextGIS and GDAL committer.

Your Answer

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

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