python import arcpy未初始化运行时错误

时间:2014-05-22 17:51:08

标签: python-2.6 arcpy

在我的组织中,我们遇到的问题是没有足够的Arc许可证。我希望能够捕获这个,而不是让python脚本炸毁我。当所有许可证都在使用时,我的脚本会在导入的arcpy线上炸弹。当有许可证时,这就像是一种魅力。

这是我的剧本的开头:

import os
import sys
import shutil
import arcpy

pathName = str(sys.argv[1])
print pathName

以下是回复:

Traceback (most recent call last):
  File "C:\Dropbox\Work\EclipseSrc\src\arcMapScripts\dluProc\arcPyNad27toNad83_Auto.py", line 4, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
    from geoprocessing import gp
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from _base import *
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 568, in <module>
    env = GPEnvironments(gp)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 565, in GPEnvironments
    return GPEnvironment(geoprocessor)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 521, in __init__
    self._refresh()
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 523, in _refresh
    envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized

2 个答案:

答案 0 :(得分:0)

您可以使用CheckProduct功能检查许可证是否可用。请参阅帮助页面中的复制/粘贴示例:

import sys
import arcpy

arcpy.env.workspace = "c:/data/world.gdb"

if arcpy.CheckProduct("ArcInfo") == "Available":
    arcpy.PolygonToLine_management("Lakes", "LakeLines")
else:
    msg = 'ArcGIS for Desktop Advanced license not available'
    print(msg)
    sys.exit(msg)

答案 1 :(得分:0)

我遇到了这个问题,而我的解决方案围绕着当时也在执行的计划任务。显然,使用桌面高级许可证,您无法同时运行两个导入arcpy的脚本。一旦计划任务完成,我就能够毫无问题地执行我的脚本。