I am running into an error. I have a set of functions which I want to import in the python Add-In script at the time of execution, but when I built Add-In with "import stats" line then tools are unresponsive. Any suggestions whether it is possible to import functions in the Add-In script?

import arcpy
import os
import pythonaddins
import stats

optfolder = "C:/temp"

class AoI(object):
"""Implementation for rectangle_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 5
        self.shape = 'Rectangle'

    def onRectangle(self, rectangle_geometry):
   """Occurs when the rectangle is drawn and the mouse button is released.
    The rectangle is a extent object."""

        extent = rectangle_geometry
        arcpy.Clip_management(r'C:/temp/ras', "%f %f %f %f" %(extent.XMin, extent.YMin, extent.XMax, extent.YMax),
                              optfolder + '/ras1', "#", "#", "NONE")
  • 1
    Can you perhaps post your code so that we can see where you are placing the import statement? – PolyGeo Feb 1 '13 at 7:59
  • Imports work fine for me. What is the stats module? If it is this, it will not work on Python 2.7: pypi.python.org/pypi/stats/0.1.2a – blah238 Feb 1 '13 at 13:02
  • No, I am not using that and instead its a custom made library for testing with Add-In. Have you tried importing that from within python Add-In? – Ibe Feb 1 '13 at 22:39
  • Importing what? – blah238 Feb 2 '13 at 2:21
  • a bit of confusion: So you simply imported above stats library not with Python 2.7, right? My question is tied to python Add-In (Python 2.7). – Ibe Feb 2 '13 at 2:26

If an unhandled exception, such as an ImportError, occurs before the add-in classes are instantiated they will become unresponsive, be given a [Missing] label, and have a red symbol for their icon in the case of items on toolbars or in menus.

You can confirm whether an import error is happening by wrapping your import statement with an exception handler and displaying its message in a message box, e.g.:

    import stats
except ImportError as e:
    pythonaddins.MessageBox(e.message, "ImportError")


I suspect this is the case here. You need to ensure that your stats module is actually discoverable by Python. You will want to read up on how importing works if you are not sure about this:

NOTE: If you are trying to package your stats module with your add-in, e.g. by placing it in the Install folder alongside your add-in .py file(s), see this thread, which suggests adding the following line to your add-in .py file before your stats import statement:


You'll need to import the sys and os modules before that as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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