I've seen some other past posts about syntax errors with Import Toolbox, but I'm not sure what's causing the issue for me.
arcpy.ImportToolbox(r"C:\LAStools\ArcGIS_toolbox\LAStools.tbx")
I've tried it with the alias parameter filled out too, made sure there's an alias in ArcGIS Pro, but keep getting the following syntax error:
SyntaxError: expected '('
I honestly have no idea where an open parenthesis is supposed to go. Anyone know any fixes for this?
Solved! Go to Solution.
So after stumbling across an old Google Groups discussion for LAStools, it turns out that this issue is specific to LAStools. My successful workaround was to use OS to run LAStools as a command like this:
import os
lidar_shp = r"C:\file_path\lidar.shp"
las_result = r"C:\file_path\lidar.las"
las_com = fr"C:\LAStools\bin\shp2las.exe -i {lidar_shp} -o {las_result}"
os.system(las_com)
Here's the full error message:
LiDAR SHP to Contour
=====================
Parameters
LiDAR Shapefile G:\Projects\PGE\TowerStormDataResearch2024\LiDARtoTOPO\Data\Birds Landing SW STA-Contra Costa SUB\Birds Landing SW STA-Contra Costa SUB.shp
Final Output G:\Projects\PGE\TowerStormDataResearch2024\LiDARtoTOPO\BirdsLandingContraCosta_contour.shp
=====================
Messages
Start Time: Wednesday, September 25, 2024 2:49:17 PM
Traceback (most recent call last):
File "G:\Projects\PGE\TowerStormDataResearch2024\LiDARtoTOPO\LiDARtoTOPO.atbx\lidar2contour.tool\tool.script.execute.py", line 83, in <module>
File "G:\Projects\PGE\TowerStormDataResearch2024\LiDARtoTOPO\LiDARtoTOPO.atbx\lidar2contour.tool\tool.script.execute.py", line 19, in lidar_process
File "G:\Projects\PGE\TowerStormDataResearch2024\LiDARtoTOPO\LiDARtoTOPO.atbx\lidar2contour.tool\tool.script.execute.py", line 68, in get_ps
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 179, in ImportToolbox
return import_toolbox(input_file, module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\toolbox_code.py", line 548, 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 522, in generate_toolbox_module
mycode = compile(code, toolbox.pathName, 'exec')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\LAStools\ArcGIS_toolbox\LAStools.tbx", line 1142
^
SyntaxError: expected '('
Failed script LiDAR SHP to Contour...
Failed to execute (lidar2contour).
Failed at Wednesday, September 25, 2024 2:54:16 PM (Elapsed Time: 4 minutes 58 seconds)
So after stumbling across an old Google Groups discussion for LAStools, it turns out that this issue is specific to LAStools. My successful workaround was to use OS to run LAStools as a command like this:
import os
lidar_shp = r"C:\file_path\lidar.shp"
las_result = r"C:\file_path\lidar.las"
las_com = fr"C:\LAStools\bin\shp2las.exe -i {lidar_shp} -o {las_result}"
os.system(las_com)