0

I'm encountering an interesting conflict between arcpy and osgeo's osr. It seems that the order in which the two modules are imported effects arcpy's ability to look into ArcSDE databases.

If you import osr after arcpy,

C:\Windows\System32>C:\Python27\ArcGISx6410.3\python.exe
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy, osr
>>> arcpy.Exists('C:\\EGS_Dev\\postgres_EGS_DEV_view.sde\\egs_admin.ops_query')
False
>>> ^Z

Then arcpy cannot look into the ArcSDE database to see the tables within.

Whereas if you import arcpy after osr,

C:\Windows\System32>C:\Python27\ArcGISx6410.3\python.exe
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import osr, arcpy
>>> arcpy.Exists('C:\\EGS_Dev\\postgres_EGS_DEV_view.sde\\egs_admin.ops_query')
True
>>> ^Z

Then arcpy can look into the database just fine.

I'm guessing that the two overwrite some reference when they are imported, meaning arcpy cannot work correctly if osr is imported after it, and vice versa.

Does anyone know what the conflict is between these two, or if there is a good resolution to the conflict (other than switching the import order depending on what is most important to the tool)?

Edit:

Upon further inspection, osgeo's ogr and gdal modules also cause issues with for arcpy looking at ArcSDEs. They do not prevent the module from seeing tables in the database (as far as I can tell), but importing either of ogr or gdal after arcpy will cause arcpy.da.ListDomains(database) to raise a RuntimeError with no descriptive text.

C:\Windows\System32>C:\Python27\ArcGISx6410.3\python.exe
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] 
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcpy
>>> import ogr, gdal
>>> database = 'C:\\EGS_Dev\\postgres_EGS_DEV_view.sde'
>>> dbDomains = arcpy.da.ListDomains(database)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError
>>> ^Z

Your Answer

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

Browse other questions tagged or ask your own question.