9

I am trying to use the mapping component of the wonderful PySAL package, but for some reason I do not have the ogr module. I was under the impression that it came packaged with gdal. Am I missing something?

import gdal
import ogr

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-29-ef9eb3418665> in <module>()
----> 1 import gdal
      2 import ogr

ImportError: No module named gdal

UPDATE: I am afraid I was in a bit of a hurry to catch a plane, so I failed to include some critical information. I already installed python-gdal using the apt-get method described here, because I wanted to leave little to chance. Is it possible that the package manager did not install it correctly?

choct155@choct155-Q550LF:~$ sudo apt-get install python-gdal
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-gdal is already the newest version.
The following packages were automatically installed and are no longer required:
  firefox-globalmenu libfftw3-3 libgeos-3.3.3 libogdi3.2 libxerces-c28
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 33 not upgraded.

I am afraid I am not finding osgeo either...

from osgeo import gdal

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-28-a04b80bf4e65> in <module>()
----> 1 from osgeo import gdal

ImportError: No module named osgeo

Additionally, I should add that I am using Ubuntu 13.04.

  • I have the same problem and I installed gdal (it says it's in /usr/bin/python2.7/dist-packages. If I run a script that has 'from osgeo import gdal', I get the following error message: 'ImportError: No module named osgeo'. Did you manage to figure it out? – user29698 Apr 29 '14 at 18:41
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. – Jason Scheirer Apr 29 '14 at 19:26
12

Use these commands:

sudo apt-get install python-gdal
sudo apt-get install gdal-bin
  • 1
    This answer basically duplicates information linked to or in the question and does nothing to explain why the module wasn't present despite having installed gdal. – Chris W Apr 17 '15 at 23:35
  • 2
    this answer actually worked for me – Rodislav Moldovan May 13 '15 at 20:52
  • 1
    not working for me – ismailsunni May 24 '16 at 4:55
  • 3
    did not work for me in Ubuntu 16.04 either – raphael Jun 29 '17 at 15:31
  • @raphael, same here. My example of gdal's osgeo package not being found after installing gdal. github.com/TileStache/TileStache/issues/… – Gabriel Fair Nov 20 '17 at 16:08
1

Normally the import should look like this:

from osgeo import gdal, ogr

But if you see "ImportError: No module named osgeo", then you didn't install the GDAL Python package correctly. (Hint: if you are using Windows, I strongly recommend this).

0

I actually just ended up upgrading all of Anaconda when the next iteration was released. I should also note that GDAL was accessible in R, so I am guessing it had something to do with the particular constellation of Python dependencies. Thanks for taking a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.