Select to view content in your preferred language

Can't list custom toolbox in ArcGIS Server's Python environment.

493
1
Jump to solution
07-06-2020 12:08 PM
by Anonymous User
Not applicable

I've developed a custom toolbox that I'd like to run from a Python script. Using the ArcGIS Pro Python environment, I can load the toolbox and execute a tool from it:

    arcpy.ImportToolbox(os.path.join(script_path, "My Toolbox.tbx"))
    arcpy.MyTool_MyToolbox(a_workspace, b_workspace, output_workspace)

This works without a problem.


However, I can't guarantee that an ArcGIS Pro license will be available (the user might have signed out of arcgis.com). I can guarantee that an ArcGIS Server license will be available, so I think I should be able to run it from ArcGIS Server's Python environment.


In Visual Studio Code, if I switch to ArcGIS Server's Python environment (C:\Python27\ArcGISx6410.8\python.exe), I get the following error when trying to execute the tool:

    'module' object has no attribute 'MyTool_MyToolbox'

If I call arcpy.ListToolboxes(), the MyToolbox toolbox is one of the toolboxes returned. However, the MyTool tool is not returned by arcpy.ListTools().

I've verified that I can list the tool in ArcGIS Pro's Python environment.
 
ArcGIS Pro 2.5.1
ArcGIS Server 10.8

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Answer provided by Amr Eldib‌:

I suspect it's because ArcGIS Pro uses Python 3.x while you're attempting to use Python 2.7
ArcGIS Server ships with Python 3.x as well
It should be found at C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3 if you used the default install location.
Try using the Python.exe at that location and see if that resolves the issue.

Switching to ArcGIS Server's Python 3.x environment solved the problem. 

Visual Studio Code doesn't automatically detect this Python environment, so you'll need to manually select this environment, or use one of the methods identified in the link to get Visual Studio Code to automatically detect it.

View solution in original post

0 Kudos
1 Reply
by Anonymous User
Not applicable

Answer provided by Amr Eldib‌:

I suspect it's because ArcGIS Pro uses Python 3.x while you're attempting to use Python 2.7
ArcGIS Server ships with Python 3.x as well
It should be found at C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3 if you used the default install location.
Try using the Python.exe at that location and see if that resolves the issue.

Switching to ArcGIS Server's Python 3.x environment solved the problem. 

Visual Studio Code doesn't automatically detect this Python environment, so you'll need to manually select this environment, or use one of the methods identified in the link to get Visual Studio Code to automatically detect it.

0 Kudos