I'm trying to read in a shapefile and keep getting a File Not Found error and this exception:

ShapefileException: Unable to open /Users/name/Documents/shapefile.shp

Here's what I've got:

import shapefile

# read the shapefile
reader = shapefile.Reader('/Users/name/Documents/shapefile.shp')

I've tried several variations of that and still get the error. The shapefile exists and it works. It's also in the same folder as the dbf and shx files. Any ideas?

  • Does "name" have a space in it?
    – Vince
    Apr 14 '19 at 20:55
  • Yes it does actually. Perhaps replace that with an underscore?
    – mike
    Apr 14 '19 at 20:57
  • That didn't work either
    – mike
    Apr 14 '19 at 21:04
  • What OS are you using?
    – user2856
    Apr 15 '19 at 0:44
  • 1
    There are enough wonky things with the path reference that you should test if os.path.exists() can find the file first.
    – Vince
    Apr 15 '19 at 1:29

What about this solution? reader = shapefile.Reader(r'/Users/name/Documents/shapefile.shp'). Just add r before the string chain. otherwise try by using the \ instead of /.

  • A raw string (r'some string') will have no effect on forward slashes and changing forward slashes to backwards will not work on a non-Windows OS.
    – user2856
    Apr 15 '19 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.