在anaconda上安装xgboost时遇到的问题

时间:2017-08-25 17:33:11

标签: python install jupyter xgboost

从git安装xgboost时(后跟" python setup.py install"),我得到如下所示的控制台消息: -

======

(C:\Users\MUSTHAFA-PC\Anaconda3) C:\Users\MUSTHAFA-PC\xgboost_install_dir\python-package>python setup.py install
Install libxgboost from: ['xgboost\\xgboost.dll']
running install
running bdist_egg
running egg_info
writing xgboost.egg-info\PKG-INFO
writing requirements to xgboost.egg-info\requires.txt
writing dependency_links to xgboost.egg-info\dependency_links.txt
writing top-level names to xgboost.egg-info\top_level.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.win-amd64\egg
running install_lib
running build_py
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\build-python.sh -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\callback.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\compat.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\core.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\libpath.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\plotting.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\rabit.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\sklearn.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\training.py -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\VERSION -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\xgboost.dll -> build\bdist.win-amd64\egg\xgboost
copying build\lib\xgboost\__init__.py -> build\bdist.win-amd64\egg\xgboost
byte-compiling build\bdist.win-amd64\egg\xgboost\callback.py to callback.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\compat.py to compat.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\core.py to core.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\libpath.py to libpath.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\plotting.py to plotting.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\rabit.py to rabit.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\sklearn.py to sklearn.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\training.py to training.cpython-35.pyc
byte-compiling build\bdist.win-amd64\egg\xgboost\__init__.py to __init__.cpython-35.pyc
installing package data to build\bdist.win-amd64\egg
running install_data
creating build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\not-zip-safe -> build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying xgboost.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
creating 'dist\xgboost-0.6-py3.5.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing xgboost-0.6-py3.5.egg
removing 'c:\users\musthafa-pc\anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg' (and everything under it)
creating c:\users\musthafa-pc\anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg
Extracting xgboost-0.6-py3.5.egg to c:\users\musthafa-pc\anaconda3\lib\site-packages
xgboost 0.6 is already the active version in easy-install.pth

Installed c:\users\musthafa-pc\anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg
Processing dependencies for xgboost==0.6
Searching for scipy==0.19.1
Best match: scipy 0.19.1
Adding scipy 0.19.1 to easy-install.pth file

Using c:\users\musthafa-pc\anaconda3\lib\site-packages
Searching for numpy==1.13.1
Best match: numpy 1.13.1
Adding numpy 1.13.1 to easy-install.pth file

Using c:\users\musthafa-pc\anaconda3\lib\site-packages
Finished processing dependencies for xgboost==0.6

(C:\Users\MUSTHAFA-PC\Anaconda3) C:\Users\MUSTHAFA-PC\xgboost_install_dir\python-package>

==========

我不知道这些警告信息的重要性,但这个过程似乎已经完成而没有错误。

但是当我尝试在jupyter笔记本中导入xgboost时(" import xgboost"),以下跟踪消息会出错: -

OSError                                   Traceback (most recent call last)
<ipython-input-1-e81c313a2b5e> in <module>()
      4 import numpy as np
      5 import matplotlib.pyplot as plt
----> 6 import xgboost

C:\Users\MUSTHAFA-PC\Anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg\xgboost\__init__.py in <module>()
      9 import os
     10 
---> 11 from .core import DMatrix, Booster
     12 from .training import train, cv
     13 from . import rabit                   # noqa

C:\Users\MUSTHAFA-PC\Anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg\xgboost\core.py in <module>()
    113 
    114 # load the XGBoost library globally
--> 115 _LIB = _load_lib()
    116 
    117 

C:\Users\MUSTHAFA-PC\Anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg\xgboost\core.py in _load_lib()
    107     if len(lib_path) == 0:
    108         return None
--> 109     lib = ctypes.cdll.LoadLibrary(lib_path[0])
    110     lib.XGBGetLastError.restype = ctypes.c_char_p
    111     return lib

C:\Users\MUSTHAFA-PC\Anaconda3\lib\ctypes\__init__.py in LoadLibrary(self, name)
    427 
    428     def LoadLibrary(self, name):
--> 429         return self._dlltype(name)
    430 
    431 cdll = LibraryLoader(CDLL)

C:\Users\MUSTHAFA-PC\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    349 
    350         if handle is None:
--> 351             self._handle = _dlopen(self._name, mode)
    352         else:
    353             self._handle = handle

OSError: [WinError 126] The specified module could not be found

显然它无法导入DMatrix,Booster作为&#34;无法找到指定的模块&#34;。

知道如何纠正这个问题吗? 我的python版本是3.5而xgboost是0.6

2 个答案:

答案 0 :(得分:0)

在导入xgboost之前,需要将g ++运行时库的路径添加到os环境路径变量中。以下代码有效:

import os

mingw_path = 'C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\bin'

os.environ['PATH'] = mingw_path + ';' + os.environ['PATH']

您可以将路径替换为您自己的目录。

答案 1 :(得分:0)

我遇到了同样的问题,因为由于某种原因,Anaconda安装中的lib文件夹的首字母大写Lib,这是造成此问题的原因。我要做的就是将文件夹名称更改为lib

C:\Anaconda3\Lib\site-packages\xgboost-0.6-py3.5.egg...

C:\Anaconda3\lib\site-packages\xgboost-0.6-py3.5.egg...

此更改未破坏任何内容,并修复了module could not be found错误。