XGBoostLibraryNotFound:无法在候选路径中找到XGBoost库,您是否安装了编译器并在根路径下运行build.sh?

23

我在移动XGBoost的Python软件包目录时遇到了这个问题。

Traceback (most recent call last): File "setup.py", line 19, in LIB_PATH = libpath'find_lib_path' File "xgboost/libpath.py", line 46, in find_lib_path 'List of candidates:\n' + ('\n'.join(dll_path))) builtin.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?

有人可以解释一下如何修复它吗? 提前致谢。

10个回答

18
当您尝试安装xgboost Python软件包但缺少xgboost二进制文件时,会收到该消息。从源代码安装xgboost Python软件包的正确方法如下(假设已安装编译器,例如gcc):
git clone --recursive https://github.com/dmlc/xgboost.git
cd xgboost
./build.sh
cd python-package
python setup.py install

我更喜欢在虚拟环境中进行。请注意,在克隆存储库时,选项--recursive是必需的,因为它还将克隆来自不同存储库的文件夹,例如dmlc-core,这对于构建xgboost是必要的。


在启用 GPU 支持构建时(http://xgboost.readthedocs.io/en/latest/build.html#building-with-gpu-support/),是否仍然需要运行 ./build.sh 来安装 Python?谢谢! - harkmug
11
$ ./build.sh zsh: 没有这个文件或目录:./build.sh - whiletrue

8
其他答案对我没有用,所以我通过Conda命令安装了xgboost,方法如下:请按此链接

只需运行conda install -c conda-forge xgboost即可。


使用此命令,但出现以下错误提示: PackagesNotFoundError:当前渠道无法获得以下软件包:
  • xgboost
当前渠道:
  • https://conda.anaconda.org/conda-forge/win-64
- Manas Kumar

7
第一个答案的建议对我没有用,让我面临着与原问题一样的错误。
如果我猜测正确,你的完整错误信息大概是这样的:
C:\Users\Matt\xgboost\python-package>python setup.py install
Traceback (most recent call last):
  File "setup.py", line 19, in <module>
    LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
  File "xgboost/libpath.py", line 49, in find_lib_path
    'List of candidates:\n' + ('\n'.join(dll_path)))
XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\Matt\xgboost\python-package\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../lib/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./lib/xgboost.dll
C:\Users\Matt\AppData\Local\Programs\Python\Python35\xgboost\xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\Matt\xgboost\python-package\xgboost\./windows/x64/Release/xgboost.dll

如果遇到这种情况,解决方案如下:
1)获取/查找/下载setup.py正在寻找的库。在xgboost文件夹中搜索.dll文件。看看能否找到类似于xgboost.dll的文件,它可能被称为libxgboost.dll。如果可以,请转到步骤2。如果找不到,可以在此处下载
2)将.dll文件复制到xgboost/python-package/xgboost文件夹中。如果该.dll文件不叫xgboost.dll(即如果它被称为libxgboost.dll),则更改名称为xgboost.dll。
3)按照Gustavo的答案所述运行命令。请注意,这些命令应从Git Bash中运行。
如果您想要一个更加全面的教程,可以参考这个教程

这更好地解释了Gustavo的解决方案。我进一步澄清,最后一行“python setup.py install”是从Anaconda提示符中运行的。 - anything_everything
非常感谢。在我的情况下,实际上搜索xgboost.dll,发现它在C:\Users\User\AppData\Roaming\Python\xgboost中,而应该是C:\Users\User\AppData\Roaming\Python\Python37\site-packages\xgboost,然后就像魔术般地开始工作了! - Hossein
1
我曾经遇到过同样的错误信息,但只需安装cmake即可轻松解决。 - lv10

4

感谢Joe Nyland这里找到了一个好的解决方案。


正如他所说(对我也有效),您需要运行以下命令:

 $ brew install gcc@5
 $ pip install xgboost

2
尝试这个方法,它对我有用:
brew install gcc-5
brew install cmake
pip install xgboost

1
谢谢,@Syed Taha。这个解决方案对我也有效! - mehakVT

0
在我的情况下(Ubuntu 16.04,带有CUDA 9.0),通过将R库包添加到cmake选项列表中,显然破坏了Python库的构建:
1)Python库安装正常运行:
cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} 
cd /tmp/xgboost/python-package && python3 setup.py install

2) 在CMake中添加'-DR_LIB=ON'开关会破坏后续的Python库安装尝试:

cmake .. -DUSE_CUDA=ON -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-${CUDA_VER} -DR_LIB=ON 
cd /tmp/xgboost/python-package && python3 setup.py install

> "XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root
> path?"

0

0
  1. 在 C:\Users\ 目录下搜索 xgboost.dll 文件。 如果您已经安装了 xgboost,则应该能够找到 xgboost.dll 文件的副本。

  2. 找到 xgboost.dll 文件后,将其复制到错误信息中提到的路径之一,例如 C:\Users\\AppData\Roaming\Python\Python37\site-packages\xgboost\。现在导入应该可以工作了。


0

1.我从Anaconda命令提示符开始进行conda安装:

(base) C:\Users\abhi.b>conda install -c anaconda py-xgboost

这导致了以下错误:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.|
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - py-xgboost -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

决定不继续这条路,因为降级Python不是我的选择。

2.然后我遵循下面链接中的“最终有效尝试”: https://medium.com/analytics-vidhya/this-is-what-you-should-do-if-you-fail-to-install-the-latest-or-an-older-version-of-xgboost-on-7942a7641eee

然而,我遇到了其他用户面临的同样错误:

>>> import xgboost as xgb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\__init__.py", line 11, in <module>
  from .core import DMatrix, Booster
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 161, in <module>
  _LIB = _load_lib()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\core.py", line 123, in _load_lib
  lib_paths = find_lib_path()
File "C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\libpath.py", line 45, in find_lib_path
  raise XGBoostLibraryNotFound(
xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./lib/xgboost.dll
C:\Users\abhi.b\Anaconda3\xgboost\xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\abhi.b\Anaconda3\lib\site-packages\xgboost\./windows/x64/Release/xgboost.dll
>>> exit() 

顺便提一下,上面发布的下载xgboost.dll的链接 - https://picnet.com.au/blog/xgboost-windows-x64-binaries-for-download/ 对我来说不太清楚,所以我决定不再跟进这个帖子。

3.最后,对我来说解决方案非常简单,打开ANACONDA提示符并输入

(base) C:\Users\abhi.b>pip install xgboost

这导致了

Collecting xgboost
  Downloading xgboost-1.2.1-py3-none-win_amd64.whl (86.5 MB)
     |████████████████████████████████| 86.5 MB 1.7 MB/s
Requirement already satisfied: scipy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.5.0)
Requirement already satisfied: numpy in c:\users\abhi.b\anaconda3\lib\site-packages (from xgboost) (1.18.5)
Installing collected packages: xgboost
Successfully installed xgboost-1.2.1

然后进入Python提示符

(base) C:\Users\abhi.b>python
>>>import xgboost as xgb

或者你可以在IDE(如Spyder等)上输入相同的命令 就这样!!


0

我在使用anaconda提示符安装xgboost时遇到了相同的错误,因为xgboost的安装干扰了一些其他预安装库的版本。通过创建虚拟环境安装xgboost解决了这个问题。

在macOS和Linux上:

python3 -m pip install --user virtualenv #Install virtualenv module
python3 -m venv env #Create a virtual environment 'env'
source env/bin/activate #Activate virtual environment
pip install xgboost #Install xgboost

在 Windows 上:
py -m pip install --user virtualenv #Install virtualenv module
py -m venv env #Create a virtual environment 'env'
.\env\Scripts\activate #Activate virtual environment
pip install xgboost #Install xgboost

请参考https://packaging.python.org/guides/installing-using-pip-and-virtual-environments获取有关虚拟环境的帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接