Why can't I import a python toolbox

1689
7
Jump to solution
07-10-2018 12:37 AM
Robertvan_Gilst
New Contributor III

Hi, 

I am using ArcGIS Desktop 10.6 and would like to publish my python toolboxes using Creategpsddraft but I am running into problems in the very early stages. It cannot read my .pyt toolbox. I get the following error:

IOError: The toolbox file d:/temp/Toolbox.pyt was not found.

I have tried it on two different computers with the same result.

I have created the toolbox.pyt in ArcCatalog and haven't changed it.

import arcpy

toolbox = "d:/temp/Toolbox.pyt"
# toolbox = "d:/temp/Toolbox1.tbx"
arcpy.ImportToolbox(toolbox)

If I uncomment the line and import the tbx (which also is just a default toolbox) it works ok.

According to this post it should work just fine.

Can someone please tell me what I am doing wrong!

Thanks Robert

0 Kudos
1 Solution

Accepted Solutions
Robertvan_Gilst
New Contributor III

I am going in a different direction now. Stumbled upon Daniel Garcia‌'s answer in this thread. Which basically boils it down to this:

  • Develop your toolbox (with multiple tools)
  • Put the code a place the server can access it
  • Run the createService on the ArcGIS Server using an adapted version of Daniel's json file.

After the service has been published you can update the code, restart the service and your new code is active right away.

I'm not sure if there are any caveats yet. But it looks to me like a more developer friendly way of publishing geoprocessing services.

Now I easily can combine all my geoprocessing tools in one toolbox, and publish all at once.

   Robert

View solution in original post

0 Kudos
7 Replies
DanPatterson_Retired
MVP Esteemed Contributor

according to 

AddToolbox—ArcPy Functions | ArcGIS Desktop 

an alias is needed

0 Kudos
Robertvan_Gilst
New Contributor III

I tried this both in the .pyt file:

class Toolbox(object):
  def __init__(self):
    """Define the toolbox (the name of the toolbox is the name of the
    .pyt file)."""
    self.label = "Toolbox"
    self.alias = "Toolbox"

    # List of tool classes associated with this toolbox
    self.tools = [Tool]

And specifying it as the extra parameter in the ImportToolbox (or the AddToolbox) method. I still get the error that the file cannot be found.

Robert

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

perhaps a different name than Toolbox... no clue now, other than that

0 Kudos
Robertvan_Gilst
New Contributor III

That doesn't help either.

Thanks for the help anyway...

0 Kudos
RandyBurton
MVP Regular Contributor

You might use ArcCatalog to check the status of Toolbox.pyt.  It there is an error in the toolbox, indicated by a red x in the catalog icon, it will give a "The toolbox file <Toolbox.pyt> was not found" message even if the path to the file is valid.  You can right click in Catalog and "Check Syntax" of the tool.

0 Kudos
Robertvan_Gilst
New Contributor III

It is a valid toolbox. Just the one generated in ArcCatalog. Haven't done anything with it .

0 Kudos
Robertvan_Gilst
New Contributor III

I am going in a different direction now. Stumbled upon Daniel Garcia‌'s answer in this thread. Which basically boils it down to this:

  • Develop your toolbox (with multiple tools)
  • Put the code a place the server can access it
  • Run the createService on the ArcGIS Server using an adapted version of Daniel's json file.

After the service has been published you can update the code, restart the service and your new code is active right away.

I'm not sure if there are any caveats yet. But it looks to me like a more developer friendly way of publishing geoprocessing services.

Now I easily can combine all my geoprocessing tools in one toolbox, and publish all at once.

   Robert

0 Kudos