1

I try to import ogr from osgeo

from osgeo import ogr

but I get the following error

ModuleNotFoundError: No module named 'osgeo'

Before I installed GDAL, if I do:

pip3 install gdal
Requirement already satisfied: gdal in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (2.4.1)

which pip
/anaconda3/bin/pip

which python
/anaconda3/bin/python
emax
  • 6,965
  • 19
  • 74
  • 141

2 Answers2

0

It will likely do with relative and absolute imports, provided you installed the package correctly. Either doing a simple module name alteration or changing where/how you import should fix this. A detailed explanation is in the top 2 answers to the question linked below.

Relative imports - ModuleNotFoundError: No module named x

Philip Bal
  • 23
  • 9
0

The issue that you are facing is mainly because you are installing the packages with pip3 and it is stored to the site-packages in the native python3.

You are running the code with the python which came with anaconda. The simplest way to solve this is to install gdal with conda.

conda install -c conda-forge gdal
Nikhil Baby
  • 863
  • 3
  • 10
  • 22