Extending geoprocessing through Python modules - toolbox not in arcpy!

3234
6
09-25-2015 04:48 PM
curtvprice
MVP Esteemed Contributor

After having it suggested by Drew Flater​ and Ghislain Prince​ at the Esri UC, I am attempting to use the extending geoprocessing guidance to make a toolbox easily accessible to ArcMap and Python as a system toolbox, using distutils.

I created a toolbox with a model in it, ran the distutil stuff (I even figured out to create an msi to install it silently!).

I can run it from ArcMap. Here's my GP dialog

Executing: Foo
Start Time: Fri Sep 25 17:30:36 2015
Executing (Calculate Value): CalculateValue "chr(12)*3 + "Hello world" + chr(12)*3" # Variant
Start Time: Fri Sep 25 17:30:36 2015
Value =    Hello world   
Succeeded at Fri Sep 25 17:30:36 2015 (Elapsed Time: 0.08 seconds)
Succeeded at Fri Sep 25 17:30:36 2015 (Elapsed Time: 0.09 seconds)

All well and good. But I don't see in arcpy as promised.

(I thought this would be available from arcpy without ImportToolbox)

>>> arcpy.Foo_footbx()
Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Foo_footbx'

Am I doing something wrong or does this only work with pyt files? The guidance seems to imply tbx files should work too.

I've attached a zip of my attempt. One thing not clear from the help - do I need to edit __init__.py or footbx.py? If so what goes there?

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

on iThingy so I cant test, but I do remember some warning about using the alias

ImportToolbox—Help | ArcGIS for Desktop

I presume you can ignore the rest

The link you provided for 10.3.1 is

http://desktop.arcgis.com/en/desktop/latest/analyze/python/extending-geoprocessing-through-python-mo...

​just in case you see any updated information

curtvprice
MVP Esteemed Contributor

The warning is that it is best practice to use a alias, which I did.

My issue is that the toolbox showed up in the System Tools as promised, but it is not available from arcpy without running ImportToolbox.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ok clear now...
The only way I have distributed toolboxes is for people to unzip a zip files which contains a script or scripts and ​a toolbox in a folder.  So people add the toolbox from the folder/location where they unzipped it. I haven't even tried to see if putting a toolbox in esri's toolbox folder works.

Both ArcGIS and ArcGIS Pro are specific about having to import toolboxes before they can be used in scripts

ImportToolbox—ArcPy Functions | ArcGIS for Desktop

ImportToolbox—Help | ArcGIS for Desktop

so according to your docs distutils is supposed to solve this.  I would contact them directly.

EDIT

of course everything is installed in the site-packages folder in python...The only other thing I can think of is if you have multiple versions of python and the correct path not being picked up...

0 Kudos
curtvprice
MVP Esteemed Contributor

of course everything is installed in the site-packages folder in python...The only other thing I can think of is if you have multiple versions of python and the correct path not being picked up.

I could buy that if I couldn't run the tool from ArcMap, but I can. The arcpy I'm using is the ArcMap python prompt so I really am mystified. I will open a support incident.

This would be pretty cool if I could figure out how to make it work. What I do now is just drop a our custom toolbox desktop install folder's ArcToolbox folder (using an msi) - which works, the toolbox shows up in the System Toolboxes, BUT my custom tools won't work from arcpy unless I import them with ImportToolbox.

DanPatterson_Retired
MVP Emeritus

Keep us posted.  I dont use arcmap's python so I can't help.  I use pythonwin and pyscripter for 2.7.x and 3.4.x

0 Kudos
AlanStewart
Occasional Contributor

I can't get my toolbox to show up in the Systems Tools. I've tried to follow the instructions at extending-geoprocessing-through-python-modules very closely. The reason may be that we do not actually install our python framework via a python installer. Our Windows installer delivers the package as a hierarchy of folders and creates a .pth file in the python Lib/site-packages folder to "install" it. Setup.py has never existed. We've been doing it this way for some time now, but without an accompanying toolbox and tools. Does anyone have relevant experience or knowledge?

0 Kudos