14

Trying to read a shapefile (.shp) and received an ImportError after executing the below line of code. I even pip installed GDAL, geopandas, fiona and shapely before executing the below code.

shapefile = gpd.read_file(r'C:\Users\....\Data Analysis\shapefiles\louisville.shp')

Error received is as follows,

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-164-16243badadbe> in <module>
----> 1 shapefile = gpd.read_file(r'C:\Users\....\Data Analysis\shapefiles\louisville.shp')

~\Anaconda3\lib\site-packages\geopandas\io\file.py in _read_file(filename, bbox, mask, rows, **kwargs)
    164     by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
    165     """
--> 166     _check_fiona("'read_file' function")
    167     filename = _expand_user(filename)
    168 

~\Anaconda3\lib\site-packages\geopandas\io\file.py in _check_fiona(func)
     78 def _check_fiona(func):
     79     if fiona is None:
---> 80         raise ImportError(
     81             f"the {func} requires the 'fiona' package, but it is not installed or does "
     82             f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"

ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: DLL load failed while importing ogrext: The specified procedure could not be found.
Abhiram
  • 498
  • 2
  • 3
  • 11

5 Answers5

9

Apparently, I was using below versions of GDAL and fiona combinations which didn't work for me.

GDAL-3.3.2-cp38-cp38-win_amd64.whl

Fiona-1.8.20-cp38-cp38-win_amd64.whl

I had to uninstall the above versions and install the below versions instead. This resolved the issue.

GDAL-3.2.3-cp38-cp38-win_amd64.whl

Fiona‑1.8.19‑cp38‑cp38‑win_amd64.whl

Abhiram
  • 498
  • 2
  • 3
  • 11
  • 2
    I am having the same problem. What are the commands to do this? – Oalvinegro Feb 13 '22 at 17:42
  • 1
    I did a 'pip install' in Anaconda Prompt. Example: pip install "D:/GDAL-3.2.3-cp38-cp38-win_amd64.whl" – Abhiram Feb 17 '22 at 05:30
  • Do you uninstall first using ```pip uninstall gdal fiona``` and then use ```pip install ``` ? Also, since your post is from Oct 2021, should I still use those versions? – prayner Jul 20 '22 at 16:11
  • fiona 1.8.19 is not available at gohlke packages as of now – lsr729 Nov 01 '22 at 19:45
2

Within Conda Forge, I force uninstalled both GDAL and Fiona, then installed Fiona 1.8.19 as suggested by Abhiram. Conda Forge installed GDAL 3.2.2 as part of this process, and the two seem to work together well.

KBurchfiel
  • 635
  • 6
  • 15
1

I had this same issue. I also removed fiona and GDAL from my conda environment and installed GDAL-3.2.2 and Fiona‑1.8.19, then installed geopandas. Fixed the issue for me. Thanks!!!

Joe G.
  • 11
  • 1
1

After struggling the whole afternoon installing pyogrio worked for me. Install by running the following command:

pip install pyogrio
Jane Kathambi
  • 695
  • 6
  • 8
0

I stumbled upon the same problem. I was able to address the issue by creating a new environment in python 3.7 and downgrading the gdal package.

With Conda Forge, after installing geopandas, I downgraded gdal to version 2.3.3 and accepted the dependency changes suggested by anaconda. Eventually I ended up with the following versions:

python 3.7.11

geopandas 0.6.1

gdal 2.3.3

fiona 1.8.4

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – user11717481 Feb 24 '22 at 09:47