简体   繁体   English

M1 Mac 返回 OSError: Library not loaded

[英]M1 Mac returns OSError: Library not loaded

I am trying to import forecasting models from the darts package using from darts. models import ExponentialSmoothing我正在尝试使用飞镖从飞镖 package 导入预测模型from darts. models import ExponentialSmoothing from darts. models import ExponentialSmoothing and the following error is returned: from darts. models import ExponentialSmoothing并返回以下错误:

OSError: dlopen(/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib Referenced from: /Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file)

I have seen a lot of people have the same issue when installing LightGBM and have tried all those fixes.我看到很多人在安装 LightGBM 时遇到了同样的问题,并尝试了所有这些修复。 I have tried brew install libomp, I have uninstalled and reinstalled Anaconda, I have used different environments, I have installed gcc and cmake and nothing has worked.我尝试过 brew install libomp,我已经卸载并重新安装了 Anaconda,我使用了不同的环境,我已经安装了 gcc 和 cmake,但没有任何效果。 I have a MacBook Pro with an M1 chip and am using Spyder with Anaconda.我有一台带有 M1 芯片的 MacBook Pro,并且正在使用带有 Anaconda 的 Spyder。 Does anyone have an answer to this?有人对此有答案吗?

My code, which is taken directly from the darts package site, and its output is as follows:我的代码直接取自飞镖 package 站点,其 output 如下:


import darts

from darts import TimeSeries

# Read a pandas DataFrame

df = pd.read_csv('/Users/sp/Documents/Skripsie/airline-passenger-traffic.csv')

# Create a TimeSeries, specifying the time and value columns

series = TimeSeries.from_dataframe(df, '1949-01', '112')

# Set aside the last 36 months as a validation series

train, val = series[:-36], series[-36:]

from darts.models import ExponentialSmoothing
Traceback (most recent call last):

  File "/var/folders/51/7qn6p5813zd3dw8p2c_t3btr0000gn/T/ipykernel_68567/3838417146.py", line 1, in <module>
    from darts.models import ExponentialSmoothing

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/darts/models/__init__.py", line 46, in <module>
    from darts.models.forecasting.gradient_boosted_model import LightGBMModel

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/darts/models/forecasting/gradient_boosted_model.py", line 13, in <module>
    import lightgbm as lgb

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/__init__.py", line 8, in <module>
    from .basic import Booster, Dataset, Sequence, register_logger

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/basic.py", line 110, in <module>
    _LIB = _load_lib()

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/basic.py", line 101, in _load_lib
    lib = ctypes.cdll.LoadLibrary(lib_path[0])

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/ctypes/__init__.py", line 460, in LoadLibrary
    return self._dlltype(name)

  File "/Users/sp/opt/anaconda3/envs/august/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)

OSError: dlopen(/Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
  Referenced from: /Users/sp/opt/anaconda3/envs/august/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so
  Reason: tried: '/usr/local/opt/libomp/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file)```

sjp00, sjp00,

Your post could have been from me almost verbatim.你的帖子可能几乎是逐字逐句地发给我的。 I went through a very similar process.我经历了一个非常相似的过程。 After pulling my hair out, this is what worked.拔掉我的头发后,这就是有效的。 TL;DR is that for Darts to work with LightGBM on an apple M1 computer conda-forge needs to be used . TL;DR 是 Darts 在苹果 M1 计算机上使用 LightGBM 需要使用 conda-forge Default conda will not work (but may at a future date).默认 conda 将不起作用(但可能在未来某个日期)。

Reading this issue helped clarify the situation, https://github.com/microsoft/LightGBM/issues/4843阅读此问题有助于澄清情况, https://github.com/microsoft/LightGBM/issues/4843

specifically, StrikerRUS's comment:具体来说,StrikerRUS 的评论:

"If I understood correctly, default conda channels lack support of macOS-arm64 packages."( https://github.com/microsoft/LightGBM/issues/4843#issuecomment-1012313487 ) “如果我理解正确,默认的 conda 通道不支持 macOS-arm64 包。”( https://github.com/microsoft/LightGBM/issues/4843#issuecomment-1012313487

and

One difference could be that I'm using Conda instead of miniconda?一个区别可能是我使用的是 Conda 而不是 miniconda?

Yeah.是的。 That is my main assumption.这是我的主要假设。 I believe that LightGBM is being compiled for arm64 architecture but conda (and Python) is x64-based and is run via Rosetta 2 translation.我相信 LightGBM 正在为 arm64 架构编译,但 conda(和 Python)是基于 x64 的,并且通过 Rosetta 2 翻译运行。 So architecture mismatch happens.所以架构不匹配发生了。

( https://github.com/microsoft/LightGBM/issues/4843#issuecomment-1061332231 ) https://github.com/microsoft/LightGBM/issues/4843#issuecomment-1061332231

On my laptop which is a MacBook Pro (16-inch, 2021), with an Apple M1 Pro chip, and macOS Monterey Version 12.5.1 installed and the following conda setup:在我的笔记本电脑上,这是一台 MacBook Pro(16 英寸,2021 年),装有 Apple M1 Pro 芯片,安装了 macOS Monterey 版本 12.5.1 和以下 conda 设置:

conda info康达信息

 active environment: lightgbm_test_env active env location: /Users/bhudson/opt/anaconda3/envs/lightgbm_test_env shell level: 2 user config file: /Users/bhudson/.condarc populated config files: /Users/bhudson/.condarc conda version: 4.14.0 conda-build version: 3.21.9 python version: 3.9.7.final.0 virtual packages: __osx=10.16=0 __unix=0=0 __archspec=1=x86_64 base environment: /Users/bhudson/opt/anaconda3 (writable) conda av data dir: /Users/bhudson/opt/anaconda3/etc/conda conda av metadata url: None channel URLs: https://conda.anaconda.org/conda-forge/osx-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/osx-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/r/osx-64 https://repo.anaconda.com/pkgs/r/noarch package cache: /Users/bhudson/opt/anaconda3/pkgs /Users/bhudson/.conda/pkgs envs directories: /Users/bhudson/opt/anaconda3/envs /Users/bhudson/.conda/envs platform: osx-64 user-agent: conda/4.14.0 requests/2.26.0 CPython/3.9.7 Darwin/21.6.0 OSX/10.16 UID:GID: 501:20 netrc file: None offline mode: False

This is what finally worked for me.这最终对我有用。 First make and activate a clean python 3.9 environment首先制作并激活一个干净的 python 3.9 环境

conda create -n lightgbm_test_env python=3.9
conda activate lightgbm_test_env

Make sure that conda forge is added as a channel (and that is prioritized)确保将 conda forge 添加为通道(并且具有优先级)

conda config --add channels conda-forge
conda config --set channel_priority strict

Then install all of U8Darts with LightGBM at the same time.然后使用 LightGBM 同时安装所有 U8Darts。

conda install -c conda-forge -c pytorch u8darts-all lightgbm

The "-c conda-forge" flag may not be strictly necessary, but I left it in for extra redundancy. “-c conda-forge”标志可能不是绝对必要的,但我将其保留为额外的冗余。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM