ArcHydro "EOL While Scanning String Literal" error when importing toolbox via ArcPy

1469
3
Jump to solution
09-15-2021 01:44 PM
CWest
by
New Contributor

Hi everyone,

I'm doing some work converting some models from ModelBuilder into (better functioning) python scripts. To give me a framework, I've exported the model as a .py to give me an idea as to what I should be doing with my own code. One of my tools requires me to use the ImportToolbox arcpy command to bring in the Arc Hydro Tools Pro toolbox. The path is correct and the toolbox import works fine when in ModelBuilder and the tools themselves work just fine manually in Arc Pro. But when running the same command with the same parameters I get the following error:

Traceback (most recent call last):
File "C:/Users/[USERNAME]/PycharmProjects/pythonProject/HandModel.py", line 8, in <module>
arcpy.ImportToolbox(r"C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\toolboxes\Arc_Hydro_Tools_Pro.tbx")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 185, in ImportToolbox
return import_toolbox(input_file, module_name)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\toolbox_code.py", line 491, in import_toolbox
mymodule = generate_toolbox_module(toolbox, None, False, False, False, module_name, use_alt_alias)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\toolbox_code.py", line 466, in generate_toolbox_module
'exec')
File "C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\toolboxes\Arc_Hydro_Tools_Pro.tbx", line 6403
100000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision""""
^
SyntaxError: EOL while scanning string literal

Process finished with exit code 1

 I have tried both:

arcpy.AddToolbox(r"C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\toolboxes\Arc_Hydro_Tools_Pro.tbx")
arcpy.ImportToolbox(r"C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\toolboxes\Arc_Hydro_Tools_Pro.tbx")

 and both yield the same error. Likewise, I have tried using regular strings with double slashes in case the raw string was tripping it up. My novice eye seems to think that there's some type of quote mismatch inside the toolbox itself, but if that's the case I wouldn't know how to fix it.

In terms of versions, I'm using Python 3.7.10, ArcHydro Pro 2.8.6, and ArcGIS Pro 2.8.2. This error occurred on ArcHydro Pro versions 2.6.2 and 2.8.6.

 

If anyone has any ideas as to what's going on, please feel free to chime in! I'm pretty new to this kind of scripting so I'm pretty lost. Thanks!

0 Kudos
1 Solution

Accepted Solutions
DeanDjokic
Esri Contributor

Try using the latest version of Arc Hydro Pro tools (2.8.13) that we just posted.  You can use the direct link below if the tools are not showing on the ftp site yet (takes some time for them to show up after we post them into the system).

https://downloads.esri.com/archydro/ArcHydro/Setup/Pro/2.8.13/

The problem you have seen is a problem with tool help (metadata) not with the actual python code.

I also suggest that you do not import the full Arc Hydro toolbox.  Instead import just the tools (modules) you need.  That makes the code leaner and faster.  Please review doc "Arc Hydro - Calling Arc Hydro Tools in Python" at https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-... to see how to do this.  You can also inspect some of Arc Hydro tools and see how we call other Arc Hydro tools within them for additional examples.  

View solution in original post

3 Replies
DeanDjokic
Esri Contributor

Try using the latest version of Arc Hydro Pro tools (2.8.13) that we just posted.  You can use the direct link below if the tools are not showing on the ftp site yet (takes some time for them to show up after we post them into the system).

https://downloads.esri.com/archydro/ArcHydro/Setup/Pro/2.8.13/

The problem you have seen is a problem with tool help (metadata) not with the actual python code.

I also suggest that you do not import the full Arc Hydro toolbox.  Instead import just the tools (modules) you need.  That makes the code leaner and faster.  Please review doc "Arc Hydro - Calling Arc Hydro Tools in Python" at https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-... to see how to do this.  You can also inspect some of Arc Hydro tools and see how we call other Arc Hydro tools within them for additional examples.  

CWest
by
New Contributor

Downloading 2.8.13 seemed to fix the issue let me import it. I'm still a bit confused about the executeAH stuff, but I'll do some more reading and experimenting to figure it out. Thanks for your help, Dean!

0 Kudos
DeanDjokic
Esri Contributor

Great, and thanks for marking it as a "solution".

Let me know how your work progresses with implementation of executeAH approach.  The doc I have pointed you to can use some refresh and if we can make it better based on your experience (e.g. more clearly describe the process so there is less research you need to do), I'd be happy to do so.  Feel free to reach out directly to me if you have any further questions/comments.  ddjokic@esri.com.

0 Kudos