【问题标题】:Import xgboost in anaconda?在anaconda中导入xgboost?
【发布时间】:2017-06-16 07:41:02
【问题描述】:
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4

我使用官方文档在 ubuntu 上安装 xgboost。没有错误,但是当我启动我的 ipython notebook 是 anaconda 环境时, import xgboost 显示错误,这是没有模块。

如何在我的anaconda python环境中导入xgboost?

是否需要修改ubuntu中的一些环境变量?

【问题讨论】:

  • 您可以使用 pip 安装 xgboost:pip install xgboost

标签: ubuntu xgboost


【解决方案1】:

对我来说,通过将工作文件从 xgboost.py 重命名为其他名称,问题得到了解决。

【讨论】:

    【解决方案2】:

    我在使用 Spyder 时也发生了同样的事情。 我可以使用终端导入它(带有弃用警告),即:

       pinaki@Excalibur:~$ python
       Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58) 
       [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
       Type "help", "copyright", "credits" or "license" for more information.
       >>> from xgboost import XGBClassifier
       /home/pinaki/anaconda3/lib/python3.6/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
        "This module will be removed in 0.20.", DeprecationWarning)
        >>>
    

    但是在尝试使用 Spyder 运行相同的代码时出现以下错误:

      from xgboost import XGBClassifier
      Traceback (most recent call last):
    
      File "<ipython-input-1-9b31cfdb821c>", line 1, in <module>
      from xgboost import XGBClassifier
    
      File "/media/pinaki/MyStuff/Work/Machine Learning A-Z Template Folder/Part 10 - Model Selection & Boosting/Section 49 - XGBoost/XGBoost/xgboost.py", line 30, in <module>
      from xgboost import XGBClassifier
    
      ImportError: cannot import name 'XGBClassifier'
    

    并且 pip install xgboost 返回以下输出:

       Requirement already satisfied: xgboost in /home/pinaki/xgboost/python-package
       Requirement already satisfied: numpy in /home/pinaki/anaconda3/lib/python3.6/site-packages (from xgboost)
       Requirement already satisfied: scipy in /home/pinaki/anaconda3/lib/python3.6/site-packages (from xgboost)
    

    【讨论】:

      【解决方案3】:

      请使用 conda 命令:

      conda install -c conda-forge xgboost

      https://anaconda.org/conda-forge/xgboost

      【讨论】:

        【解决方案4】:

        您必须转到xgboost 文件夹内的python-package 文件夹并运行setup.py

        之后

        git clone --recursive https://github.com/dmlc/xgboost
        cd xgboost; make -j4
        

        运行

        cd python-package; sudo python setup.py install
        

        【讨论】:

          【解决方案5】:

          使用这个 conda 命令:

          conda install -c conda-forge xgboost
          

          pip install xgboost
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-07-17
            • 2023-01-07
            • 2018-11-11
            • 2017-09-12
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多