Select to view content in your preferred language

Python Traceback "Attribute Error" when adding toolbox from USGS

810
3
04-09-2024 10:37 AM
marieadeline
Emerging Contributor

marieadeline_0-1712684063816.png

I am trying to add a Toolbox downloaded from GIS Tools | USGS Astrogeology Science Center which should be error-free. After downloading the toolbox and unzipping the file, it is showing the error message in the picture. Any help would be appreciated!

Error text:

Traceback (most recent call last):
File "<string>", line 24, in <module>
AttributeError: 'GPEnvironment' object has no attribute 'overwriteoutput'

 

0 Kudos
3 Replies
marieadeline
Emerging Contributor

I found a solution, not sure it should require correction and likely needs to be modified on the USGS site toolbox download. The error has cleared in ArcGIS Pro.

In the Script, I removed the line 24 that said "overwriteoutput". Now my only concern is that I don't understand what I just removed and the impact it may have on the processing tools...

0 Kudos
Dale_Honeycutt
Frequent Contributor

This looks like a simple typo in the code. It should be 'overwriteOutput'.  

Dale_Honeycutt_0-1712687754106.png

When you use geoprocessing tools that output a datafile to disk, such as a feature class or file, this environment setting controls what happens if the output datafile already exists on disk.  Most of the time, you just want the output datafile to be overwritten if it exists. 

If you're comfortable with editing Python code, you could change it from 'overwriteoutput' to 'overwriteOutput'.  But really, whoever provided you this code should change it.

In looking at the documentation, it appears that before version 2.9, using 'overwriteoutput' would not have thrown the AttributeError exception.  I suspect that the programmer created this code on a < 2.9 version of Pro.

https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/env.htm

You can set whether to overwrite in Pro's Project>Options, like this (it's the first option):

Dale_Honeycutt_1-1712689813389.png

 

I suspect that since you deleted the offending line in the Python code, whatever you choose in Project>Options will be in effect.

 

0 Kudos
marieadeline
Emerging Contributor

Thanks for the explanation, super helpful! I'll try correcting the typo and updating my Project Option in case this comes along again.

0 Kudos