Run Model with Python (model created in ArcGIS Pro)

4172
12
Jump to solution
11-06-2018 04:09 PM
MarkRankin1
New Contributor II

Hello All,

I'm getting the error "AttributeError: 'module' object has no attribute 'Step1CrimeDataPrep_CrimeTools'" when trying to run a model from python and the model was created in ArcGIS Pro. 

# Import arcpy module
import arcpy, datetime, sys
from time import strftime

#----------------------------------------------------------------------------


arcpy.ImportToolbox(r"\\prfsgis\giswork\PROJECTS\Crime\Crime.tbx")

arcpy.Step1CrimeDataPrep_CrimeTools()

I've done this process in models created in desktop before but this is my first attempt using models created in Pro.  Do I have to do something different?

Thanks for any help.

Cheers,

Mark Rankin

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You haven't answered either of my questions about the toolbox properties, or the scheduled task security properties.

You put the python filepath in the "Program/script:" section and the script filepath in the "Add arguments" section.

View solution in original post

12 Replies
DanPatterson_Retired
MVP Emeritus

arcpy.Step1CrimeDataPrep_CrimeTools()

is true.  arcpy doesn't have that as a property or a method

some tips here

Schedule a model—ArcGIS Pro | ArcGIS Desktop 

Is there a reason that you want to run a model in a toolbox when Pro isn't open?  Moving to a script might be an alternative

0 Kudos
Luke_Pinner
MVP Regular Contributor

Works for me.  

arcpy.ImportToolbox(r"c:\Temp\test.tbx")
<module 'test'>
arcpy.test.testfunc
<function testfunc at 0x000000003BDC4268>
arcpy.testfunc_test
<function testfunc at 0x000000003BDC4268>

Don't forget Python is case sensitive.  You may have defined the tool and/or toolbox name property as something different to Step1CrimeDataPrep and/or CrimeTools

Can you post a screenshot of the tool properties (general tab) and the toolbox (tbx) properties.  

0 Kudos
MarkRankin1
New Contributor II

Howdy All,

Thanks for the comments.  I'm using the models to run as scheduled tasks in the middle of the night.  I'm avoiding moving everything into a python script due to being more comfortable working in models and making adjustments as needed (I'm lazy).

I've included a screenshot  below of the General tab.  I've made sure to keep out underscores (that's gotten me in trouble before).  I just received a new computer so I don't know if I've not installed everything correctly (the script starts fine and writes out to a log file but when it hits the arcpy portion it errors out).

.  

Thanks for the help!

Mark

MichaelVolz
Esteemed Contributor

To test if everything for python in installed just run a simple script where you just do the arcpy import (or whatever it is for Pro).  If that throws an error, it might, but not definitely, indicate an issue with the install.

0 Kudos
Luke_Pinner
MVP Regular Contributor

Mark Rankin wrote:

I'm using the models to run as scheduled tasks in the middle of the night.

That's likely to be your problem.  Can you post some details about the scheduled task, in particular the security options in the general tab.  If you're not running the task as your user, either logged on or with stored password, you may not be able to access the \\UNC network path.

E.g.

0 Kudos
Luke_Pinner
MVP Regular Contributor

Can you also confirm that the Toolbox alias (when I said "name" previously, I meant alias) is really "CrimeTools" not "Crime".  Your tbx file is "Crime.tbx" and the alias property defaults to the filename with no extension.  Did you definitely change it to "CrimeTools"?

MarkRankin1
New Contributor II

Howdy All,

Here's an update to the forward progress.  Megan at ESRI has been helping me get to this point.  

I installed PyCharm and when changing the project interpreter to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe the script works.  Woohoo.

Megan wrote.......

  1. Open PyCharm
  2. Navigate to File > Settings
  3.  Expand Project tab > click Project Interpreter > if in the Project Interpreter section doesn't have C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe listed, you need to add it 
  4. Click on cog wheel icon > click Add Local option
  5. Click System Interpreter option on left-side panel
  6. Click the ... icon to navigate to following location and select python.exe > C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe > click OK
  7. Click OK > it might take a couple of minutes for PyCharm to set the environment to this new python executable

So now it's to what Luke was eluding to earlier...the dreaded Task Scheduler.  I have had no success getting the script to work in task scheduler.  My thought was to put the path to the python script in the "Program/script:" section and the path Megan gave me (C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe) in the "Start in (optional):" section.  This has not worked.

I'll continue on and let you all know if I find the secret combo.

Thank you all for your help.  GIS is a great community.

Cheers,

Mark

MichaelVolz
Esteemed Contributor

Are you running this scheduled task from a Windows Server?  If so, what is the version that you are running?  It appears that there are issues running Pro based scheduled tasks from a Windows Server 2012, but the scheduled tasks appear to work on a Windows Server 2016.

https://community.esri.com/message/799194-python-script-as-sheduled-task-arcgis-pro 

0 Kudos
Luke_Pinner
MVP Regular Contributor

You haven't answered either of my questions about the toolbox properties, or the scheduled task security properties.

You put the python filepath in the "Program/script:" section and the script filepath in the "Add arguments" section.