How can I solve an import error (dlopen) when trying to import python library seaborn? (M1 mac)

Viewed 20

When trying to import the seaborn package I get the below error.

The package is installed in my environment. Initially installed using conda install seaborn. After that didnt work I followed this method specified here https://www.geeksforgeeks.org/how-to-install-seaborn-on-macos/

Any help would be greatly appreciated all other packages tried work fine.

  File "<stdin>", line 1, in <module>
  File "/Users/name/folder/folder/folder/seaborn-0.11.2/seaborn/__init__.py", line 2, in <module>
    from .rcmod import *  # noqa: F401,F403
  File "/Users/name/folder/folder/folder/seaborn-0.11.2/seaborn/rcmod.py", line 7, in <module>
    from . import palettes
  File "/Users/name/folder/folder/folder/seaborn-0.11.2/seaborn/palettes.py", line 9, in <module>
    from .utils import desaturate, get_color_cycle
  File "/Users/name/folder/folder/folder/labs/seaborn-0.11.2/seaborn/utils.py", line 10, in <module>
    from scipy import stats
  File "/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/stats/__init__.py", line 453, in <module>
    from ._stats_py import *
  File "/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/stats/_stats_py.py", line 38, in <module>
    from scipy.spatial.distance import cdist
  File "/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/spatial/__init__.py", line 104, in <module>
    from ._qhull import *
ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/spatial/_qhull.cpython-39-darwin.so, 0x0002): Library not loaded: '@rpath/liblapack.3.dylib'
  Referenced from: '/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/spatial/_qhull.cpython-39-darwin.so'
  Reason: tried: '/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/bin/../lib/liblapack.3.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/envs/TU_working_with_data/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)```

1 Answers

The issue appears to be that seaborn is being loaded from outside the environment and therefore has different dynamic library links. There is advice in this post on how to isolate environments, ranging from deleting user-level sites to enabling isolation on a per-environment basis.

Also, be sure that seaborn is actually installed in the environment itself (i.e., check conda list -n TU_working_with_data seaborn).

Related