9

I have a big .pyt script (python toolbox) and now i trying split it to many files (1 file - 1 tool).

In single .pyt file everything works perfectly, but when file is splited i get this message: AttributeError: 'module' object has no attribute 'Parameter'.

Structure of files:

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 is clear.

My 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'
8
  • I followed your structure exactly and it works for me.
    – DWynne
    Commented Apr 2, 2015 at 17:01
  • 2 DWynne, what is version of your software? Commented Apr 3, 2015 at 11:42
  • I'm on 10.3 (but I could check against a different version easily enough). What version are you using?
    – DWynne
    Commented Apr 3, 2015 at 17:21
  • 1
    Running into the same problem with ArcGIS 10.3.1 Fixed it by deleting all XML files created by ArcGIS in the toolbox folder, restarted ArcGIS and Rerun the tool (not form the result window but by clicking on it). Still seems to be kind of random.
    – Thomas
    Commented Jun 20, 2015 at 10:43
  • 1
    I'm seeing this on 10.3.1 a lot, on multi file arcpy services that had been working well. I've pulled previous versions back from git that worked perfectly, cleaned the directory, cleared the services, and I'm still having weirdly random problems.
    – CMPalmer
    Commented Jun 24, 2015 at 3:35

1 Answer 1

11

This may not be the cause for everyone, but I've identified at least one set of triggers.

  1. Run Python toolbox tool from ArcCatalog
  2. Geoprocessing history is on and includes a result from #1.
  3. When starting a new ArcCatalog session, no geoprocessing windows are open initially (such as ArcToolbox window, Python window, Results window).

If the above are all true, the Python toolbox tool will show the AttributeError: 'module' object has no attribute 'Parameter' exception.

Clearing out the history (or not logging it at all) will avoid the issue, probably why I didn't see this before as I rarely retain my history.

Right-clicking on the toolbox and using refresh will clear the error, but it will come up again in the future as long as the list above remains true. However, if the tool is importing the tool class from a separate tool file (like the case above) a refresh will not be enough. For that, I had to force it by including a reload in the .pyt, and then a refresh on the toolbox will clear the error.

# Using example of toolbox.pyt above
import toolpackage.configurator  # add import
reload(toolpackage.configurator)  # add a forced reload
from toolpackage.configurator import ToolboxConfigurator
1
  • Apparently this bug still exists at 10.6-- it was driving me crazy; renaming the pyt seemed to fix it (temporarily). Using reload not only fixed it, now I can use refresh to avoid having to constantly quit and restart ArcCatalog when developing code, THANKS!! Commented Jun 4, 2018 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.