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
Solved! Go to Solution.
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.
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
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.
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
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.
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.
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"?
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.......
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
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
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.