Select to view content in your preferred language

Python tool generates an error only inside IDE

1098
6
04-24-2014 10:17 AM
MatthewBaker2
Deactivated User
All,

I'm getting a warning in Aptana writing my python code, but the script will run.

Here's my script (text in red is error / warning):

import arcpy
arcpy.CheckOutExtension("DataInteroperability")
arcpy.ImportToolbox(r"C:\GISTemp\PythonTBX")
arcpy.PythonETL()


The red text above displays the error:

Undefined variable from import, PythonETL


Not sure why the error is displaying but the script still runs...

The script runs fine on its own outside of Aptana.

-m
Tags (2)
0 Kudos
6 Replies
curtvprice
MVP Alum
It really is best practice to use a toolbox alias with arcpy, to avoid namespace collisions. Your IDE is probably picking up on the ambiguities of not having one.

Do you still have a problem if you do this:

import arcpy
arcpy.CheckOutExtension("DataInteroperability")
arcpy.ImportToolbox(r"C:\GISTemp\PythonTBX.tbx", "iop")
arcpy.PythonETL_iop() # or the equilvalent, arcpy.iop.PythonETL()
0 Kudos
MatthewBaker2
Deactivated User
Unfortunately still getting the same 'message'.... what is "iop"?

Thanks!!!

-m
0 Kudos
curtvprice
MVP Alum
what is "iop"?


"iop" is the toolbox alias or (new, better terminology) module name. These are used to keep namespaces from getting to cluttered, for example to differentiate arcpy.management.Clip() from arcpy.analysis.Clip().

I'm wondering if it's possible you have [post=369411]imported the two toolboxes with the same module name[/post] and Aptana is picking up on that. Here's a little test script I wrote to check if an module name is already loaded:

# check if an alias in the arcpy name space already
def chkalias(alias):
  try:
    exec("arcpy.{}".format(alias))
    return True
  except:
    return False

 
>>> chkalias("usgs")
False
>>> arcpy.ImportToolbox('C:\\ArcGIS\\Desktop10.1\\ArcToolbox\\Toolboxes\\USGS EGIS Tools.tbx')
<module 'usgs' (built-in)>
>>> chkalias("usgs")
True
>>>
0 Kudos
MatthewBaker2
Deactivated User
Well here's my inputs:

Toolbox and Path:
C:\GISTemp\PythonTBX

Toolbox name:
PythonTBX

Model Name (alias):
PythonETL

Joel's article goes into this issue as well, and from what I can see, my syntax should be (with relevant text in red):

import arcpy
arcpy.CheckOutExtension("DataInteroperability")
arcpy.ImportToolbox(r"C:\GISTemp\PythonTBX", "PythonETL")
arcpy.Model_PythonETL()


...which still throws the same message...

Thoughts on that?

Thanks!

-m
0 Kudos
curtvprice
MVP Alum
Is there a reason you're not using the ".tbx" file extension, like in the help for ImportToolbox?

As for my guess about multiple, conflicting module loads, a reload() cleans that out.

I'm assuming your toolbox module name/alias is "matt" (or - even if if it isn't, we are overriding it by specifying it in the ImporToolbox() call). I'm assuming your model name (not model alias/caption) is "Model".

reload(arcpy)
arcpy.ImportToolbox(r"C:\GISTemp\PythonTBX.tbx", "matt")
arcpy.Model_matt()
0 Kudos
MatthewBaker2
Deactivated User
Ooops, just an oversight not using .TBX - but - doesn't seem to make a difference.

I would bet that Aptana is having a hard time with this message, but I wouldn't be too much more concerned at this point.

Thanks again for the help!

-m
0 Kudos