Ma_
Ma_

Reputation: 13

Cannot seem to get GDAL to import into anaconda?

I installed anaconda onto my system and tried numerous ways of installing GDAL each time on Spyder it gives me the same response: ImportError: No module named gdal

I wrote the program just as follows:

import gdal

Ran it then that error

Tried:

import osgeo import gdal

same issue.

So then I installed the Anaconda prompt. And it seemed to install anaconda when I typed in:

conda install -c conda-forge gdal

I went back to Spyder and got the same error.

Any ideas of why this is happening?

In the Anaconda prompt I wrote: gdalinfo --version And got back:

GDAL 2.2.4, released 2018/03/19

All seems up to date except when I run in Spyder

Upvotes: 1

Views: 5640

Answers (2)

Diana Fuentes
Diana Fuentes

Reputation: 1

For me, it worked out by changing settings in the spyder interface:

Tools → Preferences → Python interpreter: C:/ProgramData/Anaconda2/envs/gdal/python.exe

After that change, spyder asked to run conda install ipykernel cloudpickle in the current environment. I did it and it worked. Another solution might be adding the same path (also in the spyder interface): Tools → PYTHONPATH manager.

Upvotes: 0

It can be related to the environment variables used by Spyder, so you can try to execute spyder from the command line or compare and add the missing paths in Spyder.

  • To execute from command line:

    spyder
    
  • To see missing paths:

    Enter to a Python command line and run this:

    import sys
    sys.path
    

    Then in Spyder under menu Tools > PYTHONPATH manager option add the path

Note: You should import gdal like this from osgeo import gdal, import gdal is deprecated

Hope it helps!

References:

Upvotes: 3

Related Questions