ImportError:没有名为xgboost的模块

时间:2016-11-22 17:10:01

标签: python jupyter-notebook

当我尝试从python终端导入时,我得到了这个错误,虽然我按照所有步骤安装xgboost,不知何故python无法获取包详细信息。我对python相对较新,我可以轻松安装numpy和pandas包,我使用此链接在MACOSX http://xgboost.readthedocs.io/en/latest/build.html

上安装
>>> import xgboost
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   ImportError: No module named xgboost

当我执行pip install xgboost时,我收到此错误,

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/h7/pyph_7qj6171tqp50cf2xc7m0000gn/T/pip-build-TEvbD6/xgboost/ 

我在打印sys路径时得到了这个,

  
    
      

print sys.path

    
  

[&#39;&#39;,&#39; /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip' ;,&#39; / System / Library / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7&#39;,&#39; /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin' ,&#39; /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac' ;,&#39; /System/Library/Frameworks/Python.framework/Versions/ 2.7 / lib / python2.7 / plat-mac / lib-scriptpackages&#39; /#39; /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk' ,&#39; /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old' ;,&#39; /System/Library/Frameworks/Python.framework/Versions/ 2.7 / lib / python2.7 / lib-dynload&#39;,&#39; /Library/Python/2.7/site-packages' ;,&#39; /System/Library/Frameworks/Python.framework/Versions/ 2.7 / Extras / lib / python&#39;,&#39; /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

11 个答案:

答案 0 :(得分:12)

我有同样的问题。我尝试了一切,但唯一对我有用的解决方案是直接从这里安装whl文件: http://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost

然后你可以这样做:

pip install yourFile.whl

在Windows上,我设法只需双击whl文件并安装它

祝你好运

答案 1 :(得分:8)

首先,您需要控制您的python环境。下载homebrew python,将它们粘贴到一个新的终端窗口

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

这里会提示您输入密码。安装homebrew后,使用brew install python安装python。请使用brew doctor检查您的安装,并按照自制的建议进行操作。

现在,使用新的终端窗口,从pip安装xgboost。打开terminal并将其粘贴到:

pip install xgboost

答案 2 :(得分:6)

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
sudo cp make/minimum.mk ./config.mk;
sudo make -j4;
sh build.sh
cd python-package
python setup.py install

Atleast现在我可以从macosx上的终端导入xgboost,我还没有能够在jupyter笔记本中导入它。

答案 3 :(得分:1)

仅供参考,如果您正在使用anaconda dist'n,则需要这样做

conda install -c conda-forge xgboost

答案 4 :(得分:1)

在Jupyter的终端上写这个:

> t=2019-09-13T11:33:43+0200 lvl=info msg="state check" logger=oauth queryState=d538205dcb597bec9d88dfb50fb9eb13fe1641146b0555e92f7f11780741cf03 cookieState=d538205dcb597bec9d88dfb50fb9eb13fe1641146b0555e92f7f11780741cf03
> t=2019-09-13T11:33:43+0200 lvl=eror msg="Login provider didn't return an email address" logger=context userId=0 orgId=5 uname=
> t=2019-09-13T11:33:43+0200 lvl=info msg="Request Completed" logger=context userId=0 orgId=5 uname= method=GET path=/login/generic_oauth status=302 remote_addr=10.139.55.177 time_ms=319 size=29 referer=

答案 5 :(得分:0)

尝试运行

pip install xgboost
在Anaconda提示中输入

;请务必在Anaconda提示符下执行此操作,这样它就在与您使用的Python相同的位置。

答案 6 :(得分:0)

在Pycharm上,您可以转到Pycharm>首选项,转到您拥有的解释器并安装xgboost软件包。

答案 7 :(得分:0)

在Anaconda Powershell Prompt中使用conda安装,然后使用pip install

conda install -c conda-forge xgboost
pip install xgboost

答案 8 :(得分:0)

  1. 打开终端
  2. 输入 pip install xgboost 并回车。

确保您的互联网连接良好。

不要忘记在 jupyter 中交叉检查它是否成功安装。

答案 9 :(得分:0)

试试下面的命令。

pip install xgboost
pip install plotly

答案 10 :(得分:0)

我试过了

pip install xgboost

pip3 install xgboost

但它不起作用

<块引用>

ModuleNotFoundError: 没有名为“xgboost”的模块

终于解决了 在 Jupyter Notebook 单元格中试试这个

import sys
!{sys.executable} -m pip install xgboost

结果:

Collecting xgboost
  Using cached xgboost-1.4.1-py3-none-win_amd64.whl (97.8 MB)
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.5.2)
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from xgboost) (1.19.2)
Installing collected packages: xgboost
Successfully installed xgboost-1.4.1