简体   繁体   English

在 IPython 中运行 %%cython-magic 单元时,CompileError/LinkerError: "command 'gcc' failed with exit status 1" 是什么意思

[英]What does CompileError/LinkerError: "command 'gcc' failed with exit status 1" mean, when running %%cython-magic cell in IPython

Sometimes, when I run a %%cython-cell in an IPython-notebook I get a long backtrace with ends with a quite short error message:有时,当我在 IPython 笔记本中运行 %%cython-cell 时,我会得到一个很长的回溯,并以非常短的错误消息结束:

CompileError: command 'gcc' failed with exit status 1 CompileError:命令“gcc”失败,退出状态为 1

or或者

LinkError: command 'gcc' failed with exit status 1 LinkError:命令“gcc”失败,退出状态为 1

On Windows the corresponding messages are:在 Windows 上,相应的消息是:

CompileError: command 'C:.\\Microsoft Visual Studio\\..\\cl.exe' failed with exit status X CompileError: 命令 'C:.\\Microsoft Visual Studio\\..\\cl.exe' 失败,退出状态为 X

and

LinkError: command 'C:..\\Microsoft Visual Studio\\..\\link.exe' failed with exit status YYYY LinkError: 命令 'C:..\\Microsoft Visual Studio\\..\\link.exe' 失败,退出状态为 YYYY

Is it possible to get more precise information about the underlying error?是否有可能获得有关潜在错误的更精确信息?

An example of such a %%cython-cell follows:这种 %%cython-cell 的示例如下:

[1] %load_ext Cython
[2] %%cython
    from sklearn.tree._tree cimport Node
    print("loaded")

The %%cython magic uses distutils to build the Cython-extension under the hood and IPython doesn't not capture the output gcc or other compilers/linkers log to standard error/output. %%cython魔法使用distutils在幕后构建 Cython 扩展,IPython不会捕获输出 gcc 或其他编译器/链接器日志到标准错误/输出。

In order to see the errors and warnings logged by the compiler/linker, one must go to the place where the errors are logged to by the compiler, which depends on the way the IPython was started.为了查看编译器/链接器记录的错误和警告,必须转到编译器记录错误的位置,这取决于 IPython 的启动方式。

On Linux there is another possibility: to install wurlitzer package and activate it via %load_ext wurlitzer , which would also capture the output from gcc and show it in the notebook, see also this answer .在 Linux 上还有另一种可能性:安装wurlitzer包并通过%load_ext wurlitzer激活它,这也将捕获 gcc 的输出并将其显示在笔记本中,另请参阅此答案

Sadly, wurlitzer works only on Linux, while the options bellow work for any OS.遗憾的是, wurlitzer仅适用于 Linux,而以下选项适用于任何操作系统。

IPython/Jupiter notebook: IPython/Jupiter 笔记本:

When the notebook was started from the terminal, eg via ipython notebook or similar, then the compiler output can be seen in this terminal - we see that the problem with the above cell is:当笔记本从终端启动时,例如通过ipython notebook或类似的,然后可以在该终端中看到编译器输出 - 我们看到上述单元格的问题是:

/home/ed/.cache/ipython/cython/_cython_magic_5f6d267a6f541c572b4517a74d5c9aad.c:607:31: fatal error : numpy/arrayobject.h : No such file or directory compilation terminated. /home/ed/.cache/ipython/cython/_cython_magic_5f6d267a6f541c572b4517a74d5c9aad.c:607:31:致命错误numpy/arrayobject.h :没有这样的文件或目录编译终止。

missing numpy-headers, which can be found in numpy.get_include() .缺少 numpy-headers,可以在numpy.get_include()找到。

IPython-console IPython 控制台

If IPython is started from a terminal, the errors are logged directly to the IPython console .如果 IPython 从终端启动,错误将直接记录到 IPython 控制台。 But be aware: the compiler/linker outputs will come directly at the beginning of the error-trace:但请注意:编译器/链接器输出将直接出现在错误跟踪的开头:

 >>> ipython
Python 3.7.3 (default, Mar 27 2019, 22:11:17) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.                                                                       

In [1]: %load_ext Cython                                                        

In [2]: %%cython 
   ...: from sklearn.tree._tree cimport Node 
   ...: print("loaded") 
   ...:  
   ...: 
/home/ed/.cache/ipython/cython/_cython_magic_1182f410e5c0a56b03b28dd88700704d.c:607:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
---------------------------------------------------------------------------
DistutilsExecError                        Traceback (most recent call last)
....

CompileError: command 'gcc' failed with exit status 1

The first lines tell us everything we need to know!第一行告诉我们我们需要知道的一切!

Spyder:间谍:

At least since Spyder 3.3.3, the output of the compiler/linker is seen in the IPython console (the same as in a standalone IPython-console).至少从 Spyder 3.3.3 开始,编译器/链接器的输出可以在 IPython 控制台中看到(与在独立的 IPython 控制台中相同)。


The example %%cython-cell can be fixed as follows:示例 %%cython-cell 可以修复如下:

%%cython -I <path from numpy.get_include()>
from sklearn.tree._tree cimport Node
print("loaded")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 jupyter 笔记本中运行 %%cython 时,“命令‘gcc’失败,退出状态为 1” - "command 'gcc' failed with exit status 1" when running %%cython in jupyter notebook pystan:CompileError:命令&#39;gcc&#39;失败,退出状态为1(Windows) - pystan: CompileError: command 'gcc' failed with exit status 1 (Windows) PyStan:CompileError:命令“gcc”失败,退出状态为 1(macos) - PyStan: CompileError: command 'gcc' failed with exit status 1 (macos) pystan:distutils.errors.CompileError:命令“ gcc”失败,退出状态为1 - pystan: distutils.errors.CompileError: command 'gcc' failed with exit status 1 VerificationError:CompileError:命令“ cc”失败,退出状态为1 - VerificationError: CompileError: command 'cc' failed with exit status 1 命令“gcc”失败,退出状态为 1 - command 'gcc' failed with exit status 1 Ubuntu Cython 编译错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为 1 - Ubuntu Cython compilation error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 错误:安装 psycopg2 时命令“gcc”失败并显示退出状态 - Error: command 'gcc' failed with exit status when installing psycopg2 尝试安装 OpenDR 时出现错误(命令“gcc”失败,退出状态为 1) - Error (command 'gcc' failed with exit status 1) when trying to install OpenDR 错误命令&#39;gcc&#39;失败,退出状态为1 - Error command 'gcc' failed with exit status 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM