I am currently trying to write a script that iterates through files in a folder to do geoprocessing. However, I am getting held up at the very start of my code with an error I cannot explain or find an answer to. I am basically a novice at Python scripting, however, I have used arcpy and pyscripter successfully throughout my schooling to run moderately complex scripts and have never seen this error before.
This is the error I am getting:
ERROR: File "c:\program files (x86)\arcgis\desktop10.7\ArcToolbox\Toolboxes\kml_to_shp.py", line 20, in <module>
kmlFile = sys.argv[1] # kml file<type 'exceptions.IndexError'>: list index out of range
E:\ScalesCNPP\START\GPS TRACKS\BALA\MK\KML
This is my script:
I should also mention that when I try to set arcpy.env.workspace it seems to be failing after I type in the "arcpy.env." "workspace" does not show up in the autocomplete list so I truly have no idea whats going on.
Hi Emma,
I'm curious if you try another directory for arcpy.env.workspace will you receive the same error? For example, try:
arcpy.env.workspace=r"E:\ScalesCNPP"
Hi Jake,
I get the exact same error no matter what I set the workspace as. It appears that setting the workspace environment isn’t working at all. It might be a problem with the version of python / pyscripter, howevere it has been working fine until today and I haven’t changed anything so I don’t know.
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
If you run the code in ArcMap/ArcGIS Pro, do you receive the same error?
I can run the code fine in ArcMap python window, its just when i’m using pyscripter. Im not great at running command line code, and its something I want to replicate over at least 10 folders so would like to be able to just write and edit in pyscripter where its easier to edit. I have even tried unistalling pyscripter, and reinstalling it. Honestly have no idea why its happening. It gives me the same error even when I just have “ import arcpy”
Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
Check what version of Python PyScripter is running. You can do this by clicking on the Python Versions tool in PyScripter:
Choose Setup Python Versions. What is listed under your Registered Versions?
What is the path to your python 2.7 version? See my screen shot above.