Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This is related to an old question of mine - Issues with osgeo - qgis.core and arcpy modules

Now in new versions of all the software QGIS Lisboa (1.8), ArcGIS 10.1 and pyScripter 2.5.3. They all use python 2.7

I can't get the following to work.

>>> import osgeo
>>> from osgeo import ogr

arcgis 10.1 and pyscripter fail here.

>>> import os
>>> os.chdir(r'L:\Data_Admin\QA\test_data\Boundaries\Local_Govt\TRC\TAB')
>>> driver = ogr.GetDriverByName('MapInfo File')
>>> fn='trc_boundary.tab'
>>> dataSource=driver.Open(fn,0)
>>> layer = dataSource.GetLayer(0)


feature = layer.GetFeature(0) extent=layer.GetExtent() extent (-12895.844282306107, 376810.87105960253, 7944810.84780738, 8222992.984638059) numFeatures=layer.GetFeatureCount() geometry = feature.GetGeometryRef() Traceback (most recent call last): File "", line 1, in AttributeError: 'NoneType' object has no attribute 'GetGeometryRef'

QGIS python shell fails here. Not sure why - I checked http://www.gdal.org/ogr/classOGRGeometryCollection.html but it is not helpful.


PYTHONPATH=C:\Python27\ArcGIS10.1;C:\OSGeo4W\apps\python27; C:\Program Files (x86)\Quantum GIS Lisboa

I have installed the gdal python bindings for arcgis but then where is ogr?

also I can't seem to run

from osgeo import gdal
dataset = gdal.open("c:/abc.img")

Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'open'

share|improve this question
Sounds like two rather independent questions to me. Please consider splitting it up. –  underdark Aug 9 '12 at 6:53
I want to get it to work in both the qgis and arcgis python modules...so I feel it should be connected. –  GeorgeC Aug 9 '12 at 7:01
add comment

2 Answers

There are a few odd things going on here:

  • Python is case sensitive. Thus gdal.open does not exist, but gdal.Open does exist.
  • AttributeError: 'NoneType' object has no attribute 'GetGeometryRef' means that you tried to get a feature that did not exist. I.e., layer.GetFeature(0) returned None, so there are no features in that layer.
  • "I have installed the gdal python bindings for arcgis but then where is ogr?" How doyou know? If from osgeo import gdal works, did you try from osgeo import ogr?
  • The PYTHONPATH looks busy. Are they all the same version and platform of Python?
share|improve this answer
add comment

I use ArcGIS 10 and QGIS 1.8, but I have managed to use PyScripter for both. I have recently written a blog post for this. In your case it should be easier.

My python paths for 2.7.2 is:

'C:\Windows\system32\python27.zip', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\DLLs', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\plat-win', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\lib-tk', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\qgis\bin', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages\PIL', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages\win32', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages\win32\lib', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages\Pythonwin', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\Python27\lib\site-packages\wx-2.8-msw-unicode', 'C:\Program Files (x86)\Quantum GIS Lisboa\apps\qgis\python\plugins\fTools\tools'

share|improve this answer
Thanks mate. I followed the steps and when the .color is included you get a message that the command line window color is changed and when I get rid of all that I get pyscripter can not be found and now I can't import arcpy either. Is this because 10.1 uses python 2.7. I checked the reg file you provided and it doesn't seem to mention c:\python27 where arcgis python bindings are so I ran your reg file as I assumed it wouldn't affect arcpy. –  GeorgeC Aug 9 '12 at 23:03
Blimey. OK, yes- it would make sense if you just ran the reg file as-is. I use ArcGIS10 which uses Python26. So if you just ran the reg file it would have pointed to the QGIS 2.7 install. Also, the reason of the reg file is that QGIS does not add any of the Python settings in the registry and PyScripter requires that to know which version of Python to run. In your case however, the registy settings would already been there as ArcGIS (I guess in version 10.1 as well) DOES put these reg settings. –  mapoholic Aug 10 '12 at 6:22
(continued) So basically, you will need to merge these settings (ArcGIS and QGIS) in the registry. –  mapoholic Aug 10 '12 at 6:25
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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