【问题标题】:ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly. Importing fiona resulted in:ImportError:“read_file”函数需要“fiona”包,但未安装或未正确导入。导入 fiona 导致:
【发布时间】:2021-11-29 22:18:33
【问题描述】:

尝试读取 shapefile (.shp) 并在执行以下代码行后收到 ImportError。我什至在执行以下代码之前安装了 GDAL、geopandas、fiona 和 shapely。

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

收到的错误如下,

---------------------------------------------------------------------------
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.

【问题讨论】:

    标签: python importerror fiona


    【解决方案1】:

    显然,我使用的 GDAL 和 fiona 组合的以下版本对我不起作用。

    GDAL-3.3.2-cp38-cp38-win_amd64.whl

    Fiona-1.8.20-cp38-cp38-win_amd64.whl

    我不得不卸载以上版本并安装以下版本。这解决了问题。

    GDAL-3.2.3-cp38-cp38-win_amd64.whl

    菲奥娜-1.8.19-cp38-cp38-win_amd64.whl

    【讨论】:

    • 我也有同样的问题。执行此操作的命令是什么?
    • 我在 Anaconda Prompt 中进行了“pip install”。示例:pip install "D:/GDAL-3.2.3-cp38-cp38-win_amd64.whl"
    【解决方案2】:

    在 Conda Forge 中,我强制卸载了 GDAL 和 Fiona,然后按照 Abhiram 的建议安装了 Fiona 1.8.19。 Conda Forge 安装了 GDAL 3.2.2 作为此过程的一部分,两者似乎可以很好地协同工作。

    【讨论】:

      【解决方案3】:

      我偶然发现了同样的问题。我能够通过在 python 3.7 中创建一个新环境并降级 gdal 包来解决这个问题。

      使用 Conda Forge,在安装 geopandas 后,我将 gdal 降级到 2.3.3 版并接受 anaconda 建议的依赖项更改。最终我得到了以下版本:

      python 3.7.11

      geopandas 0.6.1

      gdal 2.3.3

      菲奥娜 1.8.4

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-14
      • 2022-11-30
      • 2020-12-02
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多