【问题标题】:Why ImportError: No module named lightgbm为什么 ImportError:没有名为 lightgbm 的模块
【发布时间】:2017-10-28 00:06:48
【问题描述】:

我的操作系统是Ubuntu,我按照官方安装guide安装lightgbm。但是,当我导入它时,会引发此错误:

ImportError: 没有名为 lightgbm 的模块

我该如何解决这个问题?

在运行这些 linux 命令行后,我是否还需要去 /python-package 文件夹运行 setup.py?

【问题讨论】:

  • 你能分享你正在使用的代码吗?
  • @lmiuelvargasf 同官方指南:git clone --recursive github.com/Microsoft/LightGBM ; cd LightGBM mkdir build ; cd build cmake .. make -j
  • 您在安装时是否遇到此错误?我的意思是在你导入这个库时分享代码。
  • 安装过程中没有错误。我的导入代码是:import lightgbm as lgb
  • 你是如何运行这段代码的?

标签: python ubuntu machine-learning lightgbm


【解决方案1】:

除了运行那些 linux 命令行。我还需要去/python-package 然后运行'python setup.py install'。

【讨论】:

    【解决方案2】:

    对于 Windows 用户,如果未安装 Visual Studio(2015 或 2017),则需要 VC runtime <https://go.microsoft.com/fwlink/?LinkId=746572>

    首先通过pip install wheel 安装wheel <http://pythonwheels.com>。之后下载wheel文件并从中安装:

    pip install lightgbm
    

    【讨论】:

      【解决方案3】:

      以下应该可以解决问题:

      export PATH=/usr/local/bin/anaconda3/bin${PATH:+:${PATH}}
      PYTHONPATH=$PYTHONPATH:/usr/local/bin/anaconda3/lib/python3.6/site-packages
      

      请注意,如果您使用不同的 Python 版本,您可能需要更改路径。

      【讨论】:

        【解决方案4】:

        感谢您的上述问题和答案,有类似的问题。

        问题:

        成功安装lightgbm 后,我收到错误ImportError: No module named 'lightgbm'(在AI Platform 项目中Google Cloud 笔记本实例上的Jupyter Notebook 中)。

        问题:

        意识到lightgbm 的安装在Python 2.7 中,即使笔记本在Python 3 中运行(路径:'./.local/lib/python2.7/site-packages')。

        解决方案:

        在将 Jupyter Notebook 设置为在 Python 2 而不是 Python 3 上运行后,该错误消失了。

        【讨论】:

        • 我解决了这个错误:pip3 install lightgbm
        【解决方案5】:

        我也遇到了同样的问题,直接在笔记本上运行安装解决了

        !pip install lightgbm
        

        【讨论】:

          【解决方案6】:

          conda install -c conda-forge lightgbm 为我解决了这个问题 您只需在导入之前在笔记本单元格中运行

          【讨论】:

            猜你喜欢
            • 2013-03-11
            • 2016-08-13
            • 2012-07-26
            • 2015-06-17
            • 1970-01-01
            • 2012-12-07
            • 2012-05-23
            • 2019-07-29
            • 2015-07-04
            相关资源
            最近更新 更多