【问题标题】:Python 3 - ModuleNotFoundError: No module named 'xgboost'Python 3 - ModuleNotFoundError:没有名为“xgboost”的模块
【发布时间】:2019-09-03 14:36:41
【问题描述】:

我是 Python 3 和一般编程的新手,所以我查看了其他人的代码,只是为了开始将一个示例粘贴到 Jupyter 中。但一开始,我得到一个错误“ModuleNotFoundError: No module named 'xgboost'” 为什么这不起作用?

import pandas            as pd
import numpy             as np
import re
import sklearn
import xgboost           as xgb // error
import seaborn           as sns
import matplotlib.pyplot as plt

%matplotlib inline

import plotly.offline    as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import plotly.tools      as tls

import warnings
warnings.filterwarnings('ignore')

# Going to use these 5 base models for the stacking
from sklearn.ensemble         import (RandomForestClassifier, AdaBoostClassifier, GradientBoostingClassifier, ExtraTreesClassifier)
from sklearn.svm              import SVC
from sklearn.cross_validation import KFold

【问题讨论】:

  • 肯定有windows版本的。如果一个运行 Anaconda 的其他 cmets 包含指令,那将会很有帮助。上面的评论 (anaconda.org/anaconda/py-xgboost) (conda install -c anaconda py-xgboost) 中提供了在 python + Anaconda for Windows 64 上安装 xgboost 的链接
  • 这能回答你的问题吗? Jupyter python3 notebook cannot recognize pandas

标签: python python-3.x module xgboost


【解决方案1】:

我假设您正在运行 Anaconda,因为这是您遇到的第一个错误。你需要安装这个包:https://anaconda.org/anaconda/py-xgboost,因为你复制的代码使用它并且需要它。

你也可能会得到一个情节错误,所以安装 https://anaconda.org/plotly/plotly 并记得重新启动 Jupyter(或至少内核)。

如果您没有运行 Anaconda,请运行 pip install xgboostpip install plotly

【讨论】:

  • 是的,我确实运行 Anaconda。这个包也有windows版本吗?因为我只看到了osx和linux文件。
  • @DaNickste 我用一个支持 win64 的新 xgboost 包修改了我的答案。 anaconda.org/anaconda/py-xgboost
  • 是的,肯定有 Windows 版本。如果答案包含运行 Anaconda 的说明,那将会很有帮助。上面的评论 (anaconda.org/anaconda/py-xgboost) (conda install -c anaconda py-xgboost) 中提供了在 python + Anaconda for Windows 64 上安装 xgboost 的墨水
【解决方案2】:

我试过了

pip install xgboost

pip3 install xgboost

但它不起作用

##ModuleNotFoundError: No module named 'xgboost'

它在 Jupyter Notebook 单元中工作

import sys

!{sys.executable} -m pip install xgboost

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-26
  • 2022-01-27
  • 2020-11-20
相关资源
最近更新 更多