Python ImportError:没有名为xgboost的模块

Python ImportError:没有名为xgboost的模块,python,jupyter-notebook,Python,Jupyter Notebook,当我尝试从python终端导入时,我遇到了这个错误,尽管我按照所有步骤安装xgboost,但python无法获得包的详细信息。我对python比较陌生,我可以轻松地安装numpy和pandas包,我使用此链接在MACOSX上安装 我在打印系统路径上得到这个 打印系统路径 [“”,/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip'、/System/Library/Frameworks/python2.

当我尝试从python终端导入时,我遇到了这个错误,尽管我按照所有步骤安装xgboost,但python无法获得包的详细信息。我对python比较陌生,我可以轻松地安装numpy和pandas包,我使用此链接在MACOSX上安装

我在打印系统路径上得到这个

打印系统路径


[“”,/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip'、/System/Library/Frameworks/python2.7'、/System/Library/Frameworks/Python.framework/Versions/2.7/plat-darwin'、/System/Library/Frameworks/Frameworks/python2.7/plat-mac'、/System/Library/framework/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat mac/lib scriptpackages'、'/System/Library/Frameworks/python2.7/lib-tk'、'/System/lib/Frameworks/Versions/2.7/lib/python2.7/lib-old'、'/System/lib/lib/lib/lib/lib/lib/lib/Frameworks/python2.7/lib-dynload'、'、'/lib/lib/lib/python2.7/s/Python/2.7/site包“,”/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python“,”/System/Library/Frameworks/Python.Python.framework/Python.framework/Extras/lib/lib/Python“,“/System/Library/Frameworks/Python/Python.Python.Frameworks/Python.Frameworks/Extras/lib/lib

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
此处提示您输入密码。安装homebrew后,请使用
brew install python
安装python。请使用
brew doctor
检查您的安装,并遵循homebrew的建议

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

pip install xgboost

至少现在我可以从macosx上的终端导入xgboost,但我还不能在jupyter笔记本中导入它。

我也有同样的问题。我尝试了所有方法,但唯一有效的解决方案是直接从这里安装whl文件:

然后你可以做:

pip install yourFile.whl
在windows上,我只需双击whl文件并安装它

祝你好运

试试跑步

pip install xgboost

在Anaconda提示符中;在Anaconda提示符中执行此操作非常重要,因此它与您使用的Python位于同一位置。

FYI如果您使用的是Anaconda dist'n,则需要执行以下操作

conda install -c conda-forge xgboost

在Jupyter的终端上写下:

conda install -c anaconda py-xgboost

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

在Anaconda Powershell提示符中使用conda安装,然后使用pip安装

conda install -c conda-forge xgboost
pip install xgboost
  • 打开终端
  • 键入pip install xgboost并按enter键
  • 确保您的互联网连接良好


    别忘了在jupyter中交叉检查它的成功安装。

    尝试一下以下命令

    pip install xgboost
    pip install plotly
    
    我试过了

    pip install xgboost
    

    但它不起作用

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

    最后我解决了 在Jupyter笔记本手机里试试这个

    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
    

    嗯,模块在那里,但没有这样的类。可能它在子模块中?例如,从xgboost.xgbclassifier导入xgbclassifier导入xgbclassifier您没有命名您的本地文件
    xgboost.py
    ,是吗?导入错误:没有名为“xgboost.xgbclassifier”的模块,我尝试使用您的命令,它返回了此消息。@JohnGordon否!在jupyter n上运行它otebook,文件名不同。我是python新手,我需要导入分类器。如果你甚至不能导入xgboost,那么安装一定出了问题。你安装它的目录是什么?我的xgboost目录中没有setup.py文件,我尝试从github克隆目录。Shobhikas MacBook Air:xgboost shobhikapand$python setup.py安装python:无法打开文件'setup.py':[Errno 2]没有这样的文件或目录我从这个下载文件夹获得了setup.py,我运行了脚本setup.py,我收到了这个错误,文件“setup.py”,第29行,在LIB_PATH=libpath['find_LIB_PATH']()文件“xgboost/libpath.py”,第45行,在“查找库路径”候选列表中:\n'+('\n'.join(dll\u路径)))builtin.XGBoostLibraryNotFound:在candicate路径中找不到XGBoost Libarary,是否安装了编译器并在根路径中运行build.sh?@shobhika我更新了我的答案。请按照我的建议尝试重新安装python。如何将包安装与python链接?在github安装中永远无法找到位置错误。此解决方案是如此快速和无痛!你能把它翻译成英语吗?嗨,谢谢你的解决方案,当我运行“sh build.sh”时。它找不到文件并显示“没有这样的文件或目录”。你知道如何解决它吗?OP已经尝试安装xgboost,但又出现了一个错误。
    pip install xgboost
    
    pip3 install xgboost
    
    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