Select to view content in your preferred language

ImportToolbox using Arcpy giving Syntax Error

457
3
10-22-2023 12:47 PM
YobB1n
by
New Contributor

I just started using python with Arcgis and am struggling with the basic step of importing a custom toolbox to use in my script. I've used ImportToolbox according to the documentation as such: 

 

arcpy.ImportToolbox(r"C:\Users\matth\Documents\LAStools\LAStools\ArcGIS_toolbox\LAStools.tbx", "lastools")

 

in order to import the 'lastools' toolbox. I've confirmed this is the correct directory, and get the following error:

 

Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 171, 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 464, in generate_toolbox_module
    mycode = compile(code,
  File "C:\Users\matth\Documents\LAStools\LAStools\ArcGIS_toolbox\LAStools.tbx", line 1141
    
    ^
SyntaxError: invalid syntax

 

Is there anything obvious I'm doing wrong or is potentially a problem with the toolbox? Any help is appreciated, thanks!

 

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

If the toolbox has an alias, skip the second part of the import.

ImportToolbox—ArcGIS Pro | Documentation

 


... sort of retired...
0 Kudos
YobB1n
by
New Contributor

I tried ommitting the alias and it still gives the same issue

0 Kudos
DanPatterson
MVP Esteemed Contributor

move the toolbox (and associated scripts if applicable) into a different/simpler folder

eg c:/tools


... sort of retired...
0 Kudos