[GIS] How to import multiple python scripts in one script tool

arcgis-10.2arcpypython-2.7toolbox

ESRI gives the option to import a script directly into a tool in your toolbox, eliminating the need for managing both the toolbox and the python script it refers to.

When you press the right mouse button on a script tool in a toolbox

I have a script tool that refers to one script, but that script uses another script (stored in the same folder). I would like to import both scripts into the tool, so that I only have to manage the toolbox. ESRI only offers the option to import one script.

How can I import both (or multiple for someone else his/her case) scripts into one tool?

Best Answer

No, you cannot import multiple scripts. The script tools have been originally designed to be based on a single Python without considering users writing multimodular Python tools.

The option to zip the modules with the __main__.py file doesn't work as script tool would not understand the .zip file as its source.

Running the Python scripts outside of ArcMap first producing the compiled .pyc files and then using them for the source of the script tool doesn't work either.

Your best bet is to refactor your tool into a single file using some 3rd party tools such Breeder or manually.

If you have a large tool with many modules and don't want to refactor them into a single file and you do care about the intellectual property protection, write custom GP tools using ArcObjects and C# / Java or Python extensions with C that would work with arcpy (I'd pick this one).