'No module named 'gdal' in jupyter-lab after installing GDAL on Mac
- 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
- 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!
Solution 1:[1]
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.
Solution 2:[2]
- Find the location of _gdal.py. It should be in site packages, yourDirectoryPath/_gdal.py
- Add that directory to your python path:
export PYTHONPATH=$PYTHONPATH:yourDirectoryPath - 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.
Solution 3:[3]
If you are using Anaconda:
conda install -c conda-forge gdal
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nick Carraway |
| Solution 2 | |
| Solution 3 | Mahmoud K. |
