Select to view content in your preferred language

The exported python of a model is not running

2231
9
06-05-2017 01:13 AM
AlaaFlaifel
Occasional Contributor

“The exported python of a model is not running “

Despite the fact that the model is running successfully in Arcmap 10.5, the exported python is not running as expected.

What might be the issue here.

Please check the screenshots below for more clarification.

Thanks!

Alaa

9 Replies
JayantaPoddar
MVP Esteemed Contributor

You might like to compare the script with the code sample in Reconcile Versions.

Also verify why OUT_LOG parameter is not active in the model.



Think Location
curtvprice
MVP Esteemed Contributor

There is really no guarantee exporting to python will work, as the python environment is often different from what you have in an interactive ArcMap session. I think for this reason, Esri (unfortunately IMHO) disabled the export to Python functionality in Pro. I think this is too bad, because this is a great path to get started programming using Python and arcpy.

If you populate the output log file parameter this may give you a clue. Another way to get some feed back (error messages) is to open a command window and run the python script like this:

C:\saved\Python> cmd /c py.py

BTW please avoid spaces in pathnames, you are asking for trouble!

https://community.esri.com/people/curtvprice/blog/2016/05/07/how-to-name-things-in-arcgis?sr=search&...

AhmadSALEH1
Occasional Contributor III

Hi Alla,

I see that you have draged  "U.sde" form "Database Connections" category  then doped it in your model, is that right?

If you did this The model will work fine but when you export it as a script and run it form windows it will not work.

the solution will be by saving your SDE connection to a local folder and drag  it to your model then export as python.

AlaaFlaifel
Occasional Contributor

Thanks a lot Ahmad.

I tried your suggestions but it didn't work with me too!

0 Kudos
JoeBorgione
MVP Emeritus

Not sure if I can be of help here, but my most recent project has involved creating a checkout replica and subsequent check in.  Something that I've discovered is when you say "python, SDE, versions, replication, and connection files all in the same breath, there is bad juju to pay.  I tried to use the exact same path as the check in replica tool uses in arc map in a script and it errors out; I've gone to r"DriveLetter:\To\The\SDE_ConnectionFile"  in my script. Also, be aware that when dealing with versioning and/or replication, sometimes you will provide the feature class, and sometimes you provide the geodatabase (workspace in Python speak).

Good luck!

That should just about do it....
DanPatterson_Retired
MVP Emeritus

I definitely agree with Joe on this one.  I would also venture that sometimes the exported script gets scrambled at times.  People tend to focus on the 'visual' of the model and don't clean up the steps they have taken to get there.  You can view the steps taken in the model and rearrange them in proper order and remove unneeded elements.

Also... people often don't read the post-export requirements to make sure the script works.  

If you read that link, there are a least 10 places where a working model can fail as a script when exported. Read the link (amongst others in that section) and evaluate your workflow. 

AhmadSALEH1
Occasional Contributor III

Hi Alla, 

What is the error message that you got? 

I see that you didn't define a value for the  location of the Log file variable  (Reconcile_Versions_Log_2 = """)

it should be something like  

Reconcile_Versions_Log_2_ ="D:/Db/myLog.txt"

AlaaFlaifel
Occasional Contributor

Thanks alot foe your help 

I will check your solutions.

Best,

Alaa

0 Kudos
AlaaFlaifel
Occasional Contributor

Hi all,

I was able to run the python by using the following code instead of exported the model directly to python

"

import arcpy
arcpy.env.overwriteOutput = True
arcpy.ImportToolbox(r"E:\tools\reconcile.tbx", "TBX")
arcpy.Model1_TBX()

"

Thanks,

Alaa