Skip to content

Instantly share code, notes, and snippets.

@jkeefe
Created July 21, 2021 21:50
Show Gist options
  • Save jkeefe/6c64ea986d3ece9558236569dd667406 to your computer and use it in GitHub Desktop.
Save jkeefe/6c64ea986d3ece9558236569dd667406 to your computer and use it in GitHub Desktop.
Solve "ModuleNotFoundError: No module named 'gdal' in qgis

I was having trouble installing QGIS plugins because I kept hitting ModuleNotFoundError: No module named 'gdal'

Here's how I solved it

  • QGIS -> Preferences -> System
  • See "Current environment variables" window
  • Note the path that is called PYTHONHOME (mine was /Applications/QGIS-LTR.app/Contents/MacOS )
  • Open terminal
  • Look for gdal using find /Applications/QGIS-LTR.app/Contents -type f -name "gdal.*"
  • Note location. Mine was: /Applications/QGIS-LTR.app/Contents/Resources/python/site-packages/GDAL-3.2.1-py3.8-macosx-10.13.0-x86_64.egg/osgeo/gdal.py
  • in my .zprofile file (probably also works in .bash_profile), I added these to lines based on that last step:
export PATH="$PATH:/Applications/QGIS-LTR.app/Contents/Resources/python/site-packages"
export PATH="$PATH:/Applications/QGIS-LTR.app/Contents/Resources/python/site-packages/GDAL-3.2.1-py3.8-macosx-10.13.0-x86_64.egg/osgeo"
  • Restarted QGIS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment