xgboost 模块无法识别

问题描述 投票:0回答:2

虽然同一问题还有另一个问题,但其中所述的解决方案对我不起作用。因此,这不是重复或重新发布。我在这里发布我的问题和实施细节。

我目前正在使用 PyCharm 执行一个简单的 ML 预测任务,我想在其中使用 xgboost。到目前为止我已经执行了以下操作。

  • cd 进入虚拟环境文件夹

    $ cd My_Project

  • 激活venv

    source myproject/bin/activate

  • pip 安装 xgboost

    $ sudo pip install xgboost

  • 升级安装

    $ sudo pip install --upgrade xgboost

我还使用 Python 3.6 将 xgboost 模块添加到 pycharm 中的项目解释器中。

我尝试运行的 python 文件具有以下导入。

from numpy import loadtxt
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split

但是当我运行脚本时,我收到此错误。

从 xgboost 导入 XGBClassifier 导入错误:没有名为“xgboost”的模块

规格

  • Ubuntu 16.04
  • PyCharm
  • Python 3.6
  • 文件名:
    classifxg.py
    (不是
    xgboost.py
    - 据说会导致此问题没有模块错误根据stackoverflow上的其他问题

在这方面的任何帮助将不胜感激。

python machine-learning importerror xgboost xgbclassifier
2个回答
0
投票

我也遇到了同样的问题,但发现我的文件也被命名为

xgboost.py
,所以它试图从我自己的文件而不是依赖项中导入分类器。


0
投票

你有没有弄清楚这一点?我在 Ubuntu 22.04 上有完全相同的问题。

© www.soinside.com 2019 - 2024. All rights reserved.