import osos.environ['DYLD_LIBRARY_PATH']='/usr/local/opt/libomp/lib'import lightgbm as lgb dlopen(/Users/sentianzhenping/opt/anaconda3/lib/python3.9/site-packages/lightgbm/lib_lightgbm.so, 0x0006): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib Referenced from: /Users/sentianzhenping/opt/anaconda3/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)
时间: 2023-06-28 09:14:08 浏览: 162
详谈Python3 操作系统与路径 模块(os / os.path / pathlib)
你需要将设置 `DYLD_LIBRARY_PATH` 的代码放在 `import lightgbm` 语句之前。请修改代码如下:
```python
import os
os.environ['DYLD_LIBRARY_PATH']='/usr/local/opt/libomp/lib'
import lightgbm as lgb
```
这样就先设置好了 `DYLD_LIBRARY_PATH` 环境变量,然后再导入 LightGBM 库,就可以顺利加载共享库了。
阅读全文