1

I'm trying to import the shapefile "Metropolin_31Jul_0921.shp" to python using the following code:

    import shapefile
    stat_area_df = shapefile.Reader("Metropolin_31Jul_0921.shp")

but i keep getting this error:

    File "C:\Users\maya\Anaconda3\lib\site-packages\shapefile.py", line 291, 
    in load
    raise ShapefileException("Unable to open %s.dbf or %s.shp." % 
    (shapeName, shapeName) )
    shapefile.ShapefileException: Unable to open Metropolin_31Jul_0921.dbf 
    or Metropolin_31Jul_0921.shp.

Does anyone know what it means? I tried adding the directory but it didn't help.

  • [It is caused by an IOError](https://github.com/cleder/pyshp/blob/9b2cdd76df75b5af225b70f00eae162d886a01da/shapefile.py#L256) which might mean the file is not in the [current working directory](https://docs.python.org/3/library/os.html#os.getcwd). Try specifying the complete path to the file. – wwii Jan 01 '18 at 18:02

1 Answers1

0

Make sure that the directory which the shapefile is located in, includes all of the supporting files such as .dbf, .shx, etc. the .shp will not work without these supporting files.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Bisbot
  • 127
  • 2
  • 3
  • 9