Chloe
Chloe

Reputation: 83

No module named 'gdal' in jupyter-lab after installing GDAL on Mac

  1. My mac version is Big Sur and python version is 3.9. I used brew to install gdal. When I run gdalinfo --version, I get the standard response:

GDAL 3.2.0, released 2020/10/26

  1. But when I try import gdal in jupyter-lab, it always shows:
ModuleNotFoundError                       Traceback (most recent call last)
In  [5]:
Line 1:     import gdal

ModuleNotFoundError: No module named 'gdal'

Can anyone help me? Thanks!

Upvotes: 2

Views: 6111

Answers (3)

Nick Carraway
Nick Carraway

Reputation: 77

Have you try from osgeo import gdal?

This command works in my case, because the gdal package is installed as a sub-module of osgeo, rather than a stand-alone package.

Upvotes: 2

Lingchao Cao
Lingchao Cao

Reputation: 475

  1. Find the location of _gdal.py. It should be in site packages, yourDirectoryPath/_gdal.py
  2. Add that directory to your python path: export PYTHONPATH=$PYTHONPATH:yourDirectoryPath
  3. Try it out. If it works then add the line in step 2 to your .profile (.bashrc/.zshrc, etc)

(This was the installation note I kept for my older version of Python2 on the old Mac when it couldn't find the module)

One thing to note, the Python3 brew installed is different with Mac's built in python3, and lives in a different path, and gdal is supposed to link with this brew installed Python3, so, make sure your JupyterLab PYTHONPATH is pointed to the brew Python3.9 directory.

Upvotes: 0

Mahmoud
Mahmoud

Reputation: 11479

If you are using Anaconda:

conda install -c conda-forge gdal

Upvotes: -1

Related Questions