2

I am trying to run a 3.6.1 Python script and one of the libs I need to import is the osgeo. I've already downloaded the GDAL library because I use QGIS. I also have ArcGIS installed on this machine which has Python 2.7.1 installed with it.

When I try to run the script, I get the following error:

Traceback (most recent call last):
 File "C:\Users\username\Desktop\PostgreAccess.py", line 3, in <module>
 from osgeo import ogr
ModuleNotFoundError: No module named 'osgeo'

I don't understand why I'm getting this error. I've already tried adding a new environment variable, restarting my machine, re-downloading the GDAL for Windows. Any suggestions for troubleshooting?

I'm on Windows 10.

asked May 8, 2017 at 19:08
1
  • What is the version of python that is used when getting this error ? Commented May 9, 2017 at 14:32

1 Answer 1

3

The GDAL python bindings must be installed. Also, in non standard python (in you case from ArcGIS) you need manually add path to folder where GDAL bindings placed:

  1. Add to environment variable PYTHONHOME path where osgeo folder situated (not recommended)
  2. Put text file with osgeo folder path named gdal.pth to site-packages of your python installation.

More about #2. For example I have two different python installations:

  1. C:\Python27\
  2. C:\Program Files\nextgis

In first location the site_packages is at path: C:\Python27\Lib\site-packages

In second location the site_packages is at path: C:\Program Files\nextgis\lib\Python27\site-packages

You can copy osgeo folder in both site-packages paths and get GDAL working in both Pythons. Or point to osgeo folder via pth file.

For example you osgeo folder situated at path C:\GDAL\Python\osgeo so you just need to create C:\Python27\Lib\site-packages\gdal.pth and C:\Program Files\nextgis\lib\Python27\site-packages\gdal.pth with one line **C:\GDAL\Python**

Note: The GDAL Python bindings need to find gdal.dll (or gdal220.dll it depends on GDAL version). So this dll mast be in osgeo folder too or path to it mast be in PATH env variable.

answered May 10, 2017 at 7:29
2
  • would you mind being a little more specific with your answer (#2)? Commented May 17, 2017 at 12:13
  • 1
    I updated my answer with more details about #2. Hope this helps. Commented May 17, 2017 at 15:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.