It is common to employ ModelBuilder to help automate a time-consuming process. The model may need to run afterhours as a scheduled task, and to do that, a Python script is needed:
Usually, this executes without error. However, the code may raise an AttributeError such as:
'module' object has no attribute 'ModelName_ToolboxAlias'
Object: Tool or environment <> not found.
Calling a model through Python may raise an AttributeError because of one of the following:
To troubleshoot the exact cause, try:
- the model does not exist
- the model name is spelled incorrectly
- the toolbox alias was spelled incorrectly
- there may be spaces or underscores, or
- the model was created in ArcGIS Pro and is called with the ArcPy installed with ArcGIS for Desktop
The error differs slightly, which helps to find the exact object Python cannot find.
- AttributeError: 'module' object has no attribute 'Model'
This indicates that the model does not exist, the model name is spelled incorrectly, or there may be spaces or underscores.
- AttributeError: 'module' object has no attribute 'ToolboxAlias'
This indicates that the toolbox alias was spelled incorrectly, or there may be spaces or underscores.
Models that are newly created, as well as any models that have been edited and saved in ModelBuilder in ArcGIS Pro, cannot be used in other ArcGIS for Desktop applications. Therefore, attempts to call a model created in ArcGIS Pro with the ArcPy in Python 2.7, will raise an AttributeError. See: ModelBuilder: Migration to ArcGIS Pro
Solution or Workaround
The solutions are to:
For example, in the Toolbox Properties dialog, under Alias, remove the underscore ( _ )
- ensure the model exists
- ensure that the toolbox alias and model name are spelled correctly
- remove spaces or underscores in the names and aliases
- use the Python installed in ArcGIS Pro to call models created in ArcGIS Pro
The underscore ( _ ) can also be removed from the model or script tool Properties dialog, if necessary:
Once the underscores ( _ ) are removed from the toolbox alias and/or the tool name, the tool can be used in the Python window.