2

I'm trying to follow this tutorial to GeoPandas and am trying to import the "oceans.shp" file, which I downloaded from here (together with the .dbf, .prj, qpj, and .shx files),

When running the code

oceans = gpd.read_file('[...]\oceans.shp')

I get the error

FionaValueError: No dataset found at path '[...]\oceans.shp' using drivers: *

What am I doing wrong - can someone point me into the right direction?

9
  • 1
    Sorry if that wasn't clear. Yes, I'm using the entire path - that's just for better readability. :)
    – Ivo
    Aug 28, 2018 at 13:43
  • What other files do you have in the same directory? (there should at least be two other files with the same name but different extensions .shx and .dbf in the same directory).
    – joris
    Aug 28, 2018 at 14:46
  • If I would follow that tutorial I would first try the syntax literally without changing anything else but the data_pth variable to point where ever your data are oceans = gpd.read_file(os.path.join(data_pth, "oceans.shp")).
    – user30184
    Aug 28, 2018 at 14:53
  • @user30184 Yep, that's what I'm doing/ trying to do - then I'm encountering that error.
    – Ivo
    Aug 29, 2018 at 6:39
  • 1
    Try putting a lowercase r in front of the first quotation mark. Sometimes your path will have some letters following a backslash that python reads as an escape character (like \n for newline). So oceans = gpd.read_file(r'[...]\oceans.shp') should solve that.
    – J Kelly
    Apr 12, 2019 at 0:08

1 Answer 1

1

Are you sure you wrote the path properly?

If the file is in the same directory than the script, do this:

import os

oceans = gpd.read_file(os.path.join(os.getcwd(), 'oceans.shp')

Using os assures you that you won't have conflicts of paths when switching from windows to linux.

9
  • Many thanks for the suggestion - the error persists, however. :(
    – Ivo
    Aug 28, 2018 at 13:31
  • Do you use linux? Can you post the results of ls ./? (directory where the file and the script is)
    – ImanolUr
    Aug 28, 2018 at 13:38
  • No, it's Windows 10...
    – Ivo
    Aug 28, 2018 at 13:38
  • For that path to work the wd has to be set and the shapefile needs to be in it
    – BERA
    Aug 28, 2018 at 13:38
  • 3
    No, forward slashes are valid in Windows.
    – user2856
    Aug 30, 2018 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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