如何在 macOS virtualenv 中正确安装 xgboost python wrapper?

How to install xgboost python wrapper in macOS virtualenv properly?

在 virtualenv 下,我正在尝试使用 official installation guide 安装 python 包装器。当我做

sudo python setup.py install

我遇到错误:

Install libxgboost from: ['/Users/dmitry/dev/mlenv/xgboost/xgboost/python-package/xgboost/../../lib/libxgboost.so']
running install
running bdist_egg
running egg_info
creating xgboost.egg-info
writing xgboost.egg-info/PKG-INFO
writing dependency_links to xgboost.egg-info/dependency_links.txt
writing requirements to xgboost.egg-info/requires.txt
writing top-level names to xgboost.egg-info/top_level.txt
writing manifest file 'xgboost.egg-info/SOURCES.txt'
reading manifest file 'xgboost.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*' under directory 'xgboost/include'
warning: no files found matching '*' under directory 'xgboost/src'
warning: no files found matching '*' under directory 'xgboost/make'
warning: no files found matching '*' under directory 'xgboost/rabit'
warning: no files found matching '*' under directory 'xgboost/lib'
warning: no files found matching '*' under directory 'xgboost/dmlc-core'
warning: no previously-included files matching '*.o' found anywhere in distribution
warning: no previously-included files matching '*.a' found anywhere in distribution
warning: no previously-included files matching '*.pyo' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
writing manifest file 'xgboost.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.12-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/xgboost
copying xgboost/__init__.py -> build/lib/xgboost
copying xgboost/callback.py -> build/lib/xgboost
copying xgboost/compat.py -> build/lib/xgboost
copying xgboost/core.py -> build/lib/xgboost
copying xgboost/libpath.py -> build/lib/xgboost
copying xgboost/plotting.py -> build/lib/xgboost
copying xgboost/rabit.py -> build/lib/xgboost
copying xgboost/sklearn.py -> build/lib/xgboost
copying xgboost/training.py -> build/lib/xgboost
error: Error: setup script specifies an absolute path:

    /Users/dmitry/dev/mlenv/xgboost/xgboost/python-package/xgboost/../../lib/libxgboost.so

setup() arguments must *always* be /-separated paths relative to the
setup.py directory, *never* absolute paths.

在这个 post 中,那家伙建议从 setup.py 中删除 "include_package_data=True"。我这样做了,然后 xgboost 已经成功安装,即 python -c "import xgboost; print(xgboost.__version__)" 输出 0.6.

然而,当我在不同于 xgboost_root_dir/python-package/ 的文件夹中执行它时,我得到:

python -c "import xgboost; print(xgboost.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/dmitry/dev/mlenv/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg/xgboost/__init__.py", line 21, in <module>
    with open(VERSION_FILE) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/dmitry/dev/mlenv/lib/python3.6/site-packages/xgboost-0.6-py3.6.egg/xgboost/VERSION'

如何解决这个问题?

您可以只注释这些行,然后就可以正常工作了!

作为解决方法,我做了:

import sys
sys.path.append('<your-path-here>/xgboost/python-package')