pythonanacondacondageopandasfiona

fiona ImportError: ... Library not loaded: @rpath/libpoppler.91.dylib


I reinstalled Anaconda (Anaconda 3, Python 3.9) on my Mac (MacOs Monterey 12.2) today. I installed geopandas through conda-forge and imported it successfully in Python of my base environment (3.9.12). I then installed salem through conda-forge too and its import in Python failed, returning:

>>> import salem
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/salem/__init__.py", line 60, in <module>
    from salem.datasets import *
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/salem/datasets.py", line 32, in <module>
    from salem import utils, gis, wrftools, sio, check_crs
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/salem/utils.py", line 88, in <module>
    hash_cache_dir = _hash_cache_dir()
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/salem/utils.py", line 55, in _hash_cache_dir
    import geopandas
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/geopandas/__init__.py", line 7, in <module>
    from geopandas.io.file import _read_file as read_file  # noqa
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/geopandas/io/file.py", line 14, in <module>
    import fiona
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/__init__.py", line 85, in <module>
    with fiona._loading.add_gdal_dll_directories():
AttributeError: partially initialized module 'fiona' has no attribute '_loading' (most likely due to a circular import)

Reading this, I tried to import fiona by itself in a new console and it gave me this error message:

>>> import fiona
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/__init__.py", line 86, in <module>
    from fiona.collection import BytesCollection, Collection
  File "/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/collection.py", line 11, in <module>
    from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: dlopen(/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/ogrext.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/libpoppler.91.dylib
  Referenced from: /Users/felixlangot/opt/anaconda3/lib/libgdal.30.dylib
  Reason: tried: '/Users/felixlangot/opt/anaconda3/lib/libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/../../../libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/lib/python3.9/site-packages/fiona/../../../libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/lib/libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/bin/../lib/libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/lib/libpoppler.91.dylib' (no such file), '/Users/felixlangot/opt/anaconda3/bin/../lib/libpoppler.91.dylib' (no such file), '/usr/local/lib/libpoppler.91.dylib' (no such file), '/usr/lib/libpoppler.91.dylib' (no such file)

I don't have much experience with management of Conda packages. When I run conda list I get the following (abridged):

conda list
# packages in environment at /Users/felixlangot/opt/anaconda3:
#
# Name                    Version                   Build  Channel
boost-cpp                 1.70.0               hd59e818_1    conda-forge
branca                    0.5.0              pyhd8ed1ab_0    conda-forge
cairo                     1.16.0            h0ab9d94_1001    conda-forge
cftime                    1.6.0            py39h86b5767_1    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.2              pyhd8ed1ab_1    conda-forge
conda                     4.12.0           py39h6e9494a_0    conda-forge
expat                     2.4.4                he49afe7_0    conda-forge
fiona                     1.8.21           py39haa9df5e_0    conda-forge
folium                    0.12.1.post1       pyhd8ed1ab_1    conda-forge
fontconfig                2.13.94              h10f422b_0    conda-forge
freexl                    1.0.6                h0d85af4_0    conda-forge
geopandas                 0.10.2             pyhd8ed1ab_1    conda-forge
geopandas-base            0.10.2             pyha770c72_1    conda-forge
geos                      3.8.0                h4a8c4bd_1    conda-forge
gettext                   0.19.8.1          h7937167_1005    conda-forge
glib                      2.68.4               he49afe7_0    conda-forge
glib-tools                2.68.4               he49afe7_0    conda-forge
hdf4                      4.2.13            hefd3b78_1005    conda-forge
json-c                    0.13.1            h575e443_1002    conda-forge
kealib                    1.4.14               h31dd65d_2    conda-forge
libdap4                   3.19.1            hae55d67_1000    conda-forge
libglib                   2.68.4               hd556434_0    conda-forge
libkml                    1.3.0             hed7d534_1010    conda-forge
libspatialite             4.3.0a            h9691d84_1033    conda-forge
libzip                    1.8.0                h8b0c345_1    conda-forge
mapclassify               2.4.3              pyhd8ed1ab_0    conda-forge
munch                     2.5.0                      py_0    conda-forge
pcre                      8.45                 he49afe7_0    conda-forge
pixman                    0.38.0            h01d97ff_1003    conda-forge
poppler                   0.89.0               hd735947_5    conda-forge
poppler-data              0.4.11               hd8ed1ab_0    conda-forge
proj                      6.2.1                h773a61f_0    conda-forge
python_abi                3.9                      2_cp39    conda-forge
salem                     0.3.7              pyhd8ed1ab_0    conda-forge
tiledb                    2.2.9                he9a4fb4_0    conda-forge
xyzservices               2022.4.0           pyhd8ed1ab_0    conda-forge

I only included conda-forge packages because my post was too long to be accpeted otherwise. I can provide the full output of conda list if needed. Nevertheless, the packages seem to be all there.

Any ideas how to fix this? Thank you for your help.

Additional Info

I also tried

conda create -n test
conda activate test
conda install -c conda-forge fiona

and the installation was again successful. However, import fiona in Python of test environment still gives the same error message.

Related Issue

This post on GitHub seems to treat a very similar issue: https://github.com/conda-forge/geopandas-feedstock/issues/64. However, it is from 2019 and was closed before the problem was fixed, so it did not help me.


Solution

  • I'm going to give the same advice as on the GitHub issue and which Conda Forge has in their documentation: don't mix channels. Channel mixing is the most common cause of all dynamic library issues.

    No issue with Conda Forge only

    Creating an environment from scratch with the YAML

    so-fiona

    so-fiona.yaml

    name: so-fiona
    channels:
      - conda-forge
    dependencies:
      - python=3.9
      - fiona
      - salem
    

    and conda env create -f so-fiona.yaml, works fine on all major platforms.