Skip to content

In ArcGIS toolbox, Find and XXXXX tools fail with SyntaxError: invalid syntax (<string>, line 1) and the message: Could not import Python module ""['os.path']"" #21

@jjrob

Description

@jjrob

For example, the Find and Convert ArcGIS Rasters to Polygons tool fails like this:

Finding ArcGIS rasters and inserting rows into table "<GeoEco.Datasets.SQLite.SQLiteTable object at 0x000001C9B9D6D490>": workspace="C:\Users\Jason\AppData\Local\Temp\ArcGISProTemp1768\Untitled\Test\Rasters", wildcard="*", searchTree=False, rasterType="None"
Finished inserting rows: 0:00:01 elapsed, 0 rows inserted, 0:00:00 per row.
Updating field "outputFeatureClass" in "table work of SQLite in-memory database 0x000001C9B9CEDC60"...
SyntaxError: invalid syntax (<string>, line 1)
The following consequences resulted from the original error:
Could not import Python module ""['os.path']"".
Could not calculate field "outputFeatureClass" in "table work of SQLite in-memory database 0x000001C9B9CEDC60".
Traceback (most recent call last):
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\ArcToolbox\Marine Geospatial Ecology Tools.atbx\ArcGISRasterFindAndConvertToPolygons.tool\tool.script.execute.py", line 14, in <module>
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\ArcToolbox\Marine Geospatial Ecology Tools.atbx\ArcGISRasterFindAndConvertToPolygons.tool\tool.script.execute.py", line 11, in Main
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\ArcToolbox.py", line 641, in _ExecuteMethodAsGeoprocessingTool
    results = method(**argValues)
  File "<string>", line 7, in FindAndConvertToPolygons
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\BatchProcessing.py", line 2050, in ExecuteFindAndProcessMethod
    eval('%s.%s(%s)' % (calculateFieldMethodMetadata.Class.Name, calculateFieldMethodMetadata.Name, args))
  File "<string>", line 1, in <module>
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\DataManagement\Fields.py", line 113, in CalculateField
    cls.CalculateFields(table, [field], [pythonExpression], where, modulesToImport, statementsToExecFirst, statementsToExecPerRow)
  File "C:\Users\Jason\AppData\Local\ESRI\conda\envs\arcgispro-py3-mget-3.1.1-release-test\Lib\site-packages\GeoEco\DataManagement\Fields.py", line 51, in CalculateFields
    exec('import ' + str(m))
  File "<string>", line 1
    import "['os.path']"
           ^
SyntaxError: invalid syntax
Failed script Find and Convert ArcGIS Rasters to Polygons...
Failed to execute (ArcGISRasterFindAndConvertToPolygons).
Failed at Monday, January 13, 2025 11:17:42 AM (Elapsed Time: 23.86 seconds)

The problem is that the list of modules to import is being passed to the toolbox script that wraps MGET as a literal string, or that script is interpreting at such, rather than interpreting it as a list. This problem is not detected by MGET's test code because it only occurs when you invoke MGET from ArcGIS itself.

The bug is probably in ArcToolbox.py, which generates the toolbox scripts.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions