导入 lightgbm 返回非零退出状态 2

import lightgbm returned non-zero exit status 2

我是 运行 Windows 10. 今天我使用

通过 anaconda 安装了 lightgbm

conda install -c conda-forge lightgbm

但是,当我尝试导入 lightgbm (运行 Jupyter Notebook) 时,我得到了以下错误跟踪:

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-2-5dacb4a27011> in <module>
----> 1 import lightgbm as lgb

D:\RI[=10=]Teaching Materials\QTDM-II\P30 LGBM\lightgbm.py in <module>
     10 
     11 from subprocess import check_output
---> 12 print(check_output(["ls", "../input"]).decode("utf8"))
     13 
     14 # Any results you write to the current directory are saved as output.

~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    334 
    335     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 336                **kwargs).stdout
    337 
    338 

~\Anaconda3\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    416         if check and retcode:
    417             raise CalledProcessError(retcode, process.args,
--> 418                                      output=stdout, stderr=stderr)
    419     return CompletedProcess(process.args, retcode, stdout, stderr)
    420 

CalledProcessError:Command '['ls', '../input']' returned non-zero exit status 2.

什么阻止我导入 lightgbm

更新:- 认为这是一个 Windows 问题,我在 Ubuntu (Oracle VB) 上安装了 Anaconda 并尝试导入。不幸的是,同样的错误也发生在这个环境中。这背后可能是什么?

看起来你的 PYTHONPATH 中有 D:\RI[=23=]Teaching Materials\QTDM-II\P30 LGBM\,你可以通过以下方式在笔记本中查看:

import sys
print(sys.path)

或在命令行上

echo %PYTHONPATH%

如果您在该目录中启动笔记本,该目录将位于 python 路径中。 因为你在 python 路径中有那个目录,所以当你尝试导入模块 lightgbm 时,python 正在寻找 lightgbm.py 文件然后导入它,并且在那个文件中你有脱壳的代码到 'ls ../input' 而你在 Windows 上没有 'ls',因此出现错误。第二种可能性是 ls 命令看不到 ../input 因为文件不存在。这并不重要,问题仍然是 import 语句在找到您使用 conda 安装并实际想要导入的 lightgbm 模块之前找到 lightgbm.py 文件。 (Hacky 修复方法是将 lightgbm.py 重命名为其他名称)

修复您的 PYTHONPATH,您可以通过以下方式取消设置:https://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10