Tengo un gran script .pyt (caja de herramientas de Python) y ahora intento dividirlo en muchos archivos (1 archivo - 1 herramienta).
En un solo archivo .pyt todo funciona perfectamente, pero cuando el archivo está dividido recibo este mensaje: AttributeError: el objeto 'módulo' no tiene el atributo 'Parámetro'.
Estructura de archivos:
My Catalog:
-- toolbox.pyt
-- toolpackage:
---- configurator.py
---- __init__.py
toolbox.pyt:
# This Python file uses the following encoding: utf-8
import arcpy
from toolpackage.configurator import ToolboxConfigurator
class Toolbox(object):
  def __init__(self):
    """Define the toolbox (the name of the toolbox is the name of the .pyt file)."""
    self.label = "label"
    self.alias = "Tools"
    # List of tool classes associated with this toolbox
    self.tools = [ToolboxConfigurator]
configurator.py:
# This Python file uses the following encoding: utf-8
import arcpy
class ToolboxConfigurator(object):
  def __init__(self):
    """Define the tool (tool name is the name of the class)."""
    self.label              = u"config"
    self.description        = u""
    self.canRunInBackground = False
  def getParameterInfo(self):
    """Define parameter definitions"""
    new_config_file   = arcpy.Parameter(
      displayName     = u"?",
      name            = "new_config_file",
      datatype        = "GPBoolean",
      parameterType   = "Optional",
      direction       = "Input")
    parameters = [new_config_file]
    return parameters
  def isLicensed(self):
    """Set whether tool is licensed to execute."""
    return True
  def updateParameters(self, parameters):
    """Modify the values and properties of parameters before internal validation
    is performed.  This method is called whenever a parameter has been changed."""
    return
  def updateMessages(self, parameters):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return
  def execute(self, parameters, messages):
    """The source code of the tool."""
__init__.py es claro.
Mi error:
Traceback (most recent call last):
  File "C:\tools_v4\toolpackage\configurator.py", line 15, in getParameterInfo
    new_config_file   = arcpy.Parameter(
AttributeError: 'module' object has no attribute 'Parameter'
                    
                        arcpy
                                python-toolbox
                                attributeerror
                                
                    
                    
                        Vladimir Ivanov
fuente
                
                fuente

Respuestas:
Puede que esta no sea la causa de todos, pero he identificado al menos un conjunto de desencadenantes.
Si todo lo anterior es cierto, la herramienta de caja de herramientas Python mostrará la
AttributeError: 'module' object has no attribute 'Parameter'excepción.Borrar el historial (o no registrarlo en absoluto) evitará el problema, probablemente por qué no vi esto antes, ya que rara vez conservo mi historial.
Al hacer clic con el botón derecho en la caja de herramientas y usar la actualización, se borrará el error, pero volverá a aparecer en el futuro, siempre y cuando la lista anterior sea verdadera. Sin embargo, si la herramienta está importando la clase de herramienta desde un archivo de herramienta separado (como en el caso anterior), una actualización no será suficiente. Para eso, tuve que forzarlo al incluir un
reloaden el .pyt, y luego una actualización en la caja de herramientas borrará el error.fuente