Problem with Python for Everyone ESRI course; path error

597
3
Jump to solution
03-24-2021 05:59 PM
SarahBlake
New Contributor III

Hi.  I saw an older post about this exact same problem, though the solution offered (an error in the path) does not seem to be the problem, or at least I can't see what is the problem after over an hour on this specific part of Exercise 3 in the 'Python for Everyone' course.  Here is my screenshot from PyCharm showing my code and the error message:

SarahBlake_0-1616633168813.png

OK, that seems pretty small so here is my code again:

Assign variables to the shapefiles
park = "Parks_sd.shp"
school = "Schools_sd.shp"
sewer = "Sewer_Main_sd.shp"

#Create a list of shapefile variables
shapeList = [park, school, sewer]

#Create and open new text file for updated shapefile
path = r"C:\EsriTraining\PythEveryone\CreatingScripts\SanDiegoUpd.txt"
file = open(path, 'w')

#Update the names of the shapefiles in shapefile list
for shp in shapeList:
print(shp)
shp = shp.replace("sd", "SD")
print(shp)
file.write(shp + "\n")

file.close()

and here is the error message at the bottom:

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" C:/EsriTraining/PythEveryone/PythEveryone/CreatingScripts/SanDiegoShapefiles.py
Traceback (most recent call last):
File "C:/EsriTraining/PythEveryone/PythEveryone/CreatingScripts/SanDiegoShapefiles.py", line 11, in <module>
file = open(path, 'w')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\EsriTraining\\PythEveryone\\CreatingScripts\\SanDiegoUpd.txt'

Process finished with exit code 1

 

I think my problem (based on my error message, and the older post about this) is the path.  The ESRI module says it should say: 

path = r"C:\EsriTraining\PythEveryone\CreatingScripts\SanDiegoUpd.txt"

When I went into my File explorer and checked to see if the Path was valid, is seemed to be, though there was no SanDiegoUpd text file there (I assume because the script failed and didn't create this file).  There was an empty such text file in the "Solutions" folder (instead of in "Creating Scripts" folder) so I later copied and pasted that into CreatingScripts, thinking that perhaps the text file had to exist to start with, but same result of error message above.  Not sure what I am doing wrong??

Thanks,

Sarah

 
 

 

 

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

Looks like the folder r"C:\EsriTraining\PythEveryone\CreatingScripts" doesn't exist.

Based on the bit of your error message that shows the name of your script, it should be r"C:\EsriTraining\PythEveryone\PythEveryone\CreatingScripts\SanDiegoUpd.txt"

Note the "PythEveryone\PythEveryone"

View solution in original post

0 Kudos
3 Replies
Luke_Pinner
MVP Regular Contributor

Looks like the folder r"C:\EsriTraining\PythEveryone\CreatingScripts" doesn't exist.

Based on the bit of your error message that shows the name of your script, it should be r"C:\EsriTraining\PythEveryone\PythEveryone\CreatingScripts\SanDiegoUpd.txt"

Note the "PythEveryone\PythEveryone"

0 Kudos
SarahBlake
New Contributor III

Thanks so much! That was it.  Silly mistake of mine, not to notice my extra "PythEveryone" folder...

Just tried it again and it worked!

0 Kudos
UriGilad_EsriAu
Esri Contributor

Hi @SarahBlake,

I've ran the script as is (just changed the output directory) and it worked fine. The script creates a new file so there's no need for you to create one manually.

Your problem is with the path. Do you have permissions to write to folders directly under C drive? Try other locations such as

path = r"C:\Users\yourusername\Downloads\SanDiegoUpd.txt"

or D drive. Copy the folder address directly from the explorer window to avoid errors.

If this answer solved your question or if you found it helpful please mark it accordingly to help others who have the same question.

 

0 Kudos