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.

Marvin Ward Jr
  • 499
  • 2
  • 7
  • 15
  • 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? –  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

3 Answers3

12

Use these commands:

sudo apt-get install python-gdal
sudo apt-get install gdal-bin
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Marouane
  • 131
  • 1
  • 3
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).

Mike T
  • 42,095
  • 10
  • 126
  • 187
1

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.

Marvin Ward Jr
  • 499
  • 2
  • 7
  • 15