启动 Intel python3.7 shell 时出现意外错误:无法执行任何命令 - 中止错误

Posted

技术标签:

【中文标题】启动 Intel python3.7 shell 时出现意外错误:无法执行任何命令 - 中止错误【英文标题】:Unexpected error when Intel python3.7 shell is launched : impossible to do any command - abort error 【发布时间】:2021-10-05 21:02:56 【问题描述】:

当我在 Debian 10 上启动 Intel python3 shell 后执行简单命令 a=1(或任何其他命令)时出现以下错误:

Python 3.7.11 (default, Sep  9 2021, 02:06:38)
[GCC 9.3.0] :: Intel Corporation on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
(imported glob)
(imported re)
>>> a=1
free(): invalid pointer
zsh: abort      /opt/intel/oneapi/intelpython/python3.7/bin/python3.7

发生了什么?

权限似乎没问题:

-rwxrwxr-x 1 19712 20M Sep  9 04:16 /opt/intel/oneapi/intelpython/python3.7/bin/python3.7

我不明白。

编辑 1

python3 上的 gdb 允许获取更多信息:

gdb python3
GNU gdb (Debian 8.2.1-2+b3) 8.2.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python3...done.
(gdb) file python3
Load new symbol table from "python3"? (y or n) y
Reading symbols from python3...done.
(gdb) r
Starting program: /opt/intel/oneapi/intelpython/python3.7/bin/python3
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Python 3.7.11 (default, Sep  9 2021, 02:06:38)
[GCC 9.3.0] :: Intel Corporation on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
(imported glob)
(imported re)
>>> a=1
free(): invalid pointer

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff7c56535 in __GI_abort () at abort.c:79
#2  0x00007ffff7cad508 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7db828d "%s\n")
    at ../sysdeps/posix/libc_fatal.c:181
#3  0x00007ffff7cb3c1a in malloc_printerr (str=str@entry=0x7ffff7db643b "free(): invalid pointer")
    at malloc.c:5341
#4  0x00007ffff7cb542c in _int_free (av=<optimized out>, p=<optimized out>, have_lock=<optimized out>)
    at malloc.c:4165
#5  0x00005555555f7abd in PyOS_Readline (sys_stdin=<optimized out>,
    sys_stdout=0x7ffff7df0760 <_IO_2_1_stdout_>, prompt=0x7ffff7656f20 ">>> ")
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/myreadline.c:377
#6  0x0000555555704c02 in tok_nextc (tok=0x55555633ca00)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/tokenizer.c:939
#7  0x000055555572c017 in tok_get (p_end=<optimized out>, p_start=<optimized out>, tok=<optimized out>)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/tokenizer.c:1373
#8  PyTokenizer_Get (p_end=<optimized out>, p_start=<optimized out>, tok=<optimized out>)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/tokenizer.c:1835
#9  parsetok (tok=<optimized out>, g=<optimized out>, start=<optimized out>, err_ret=<optimized out>,
    flags=<optimized out>) at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/parsetok.c:208
#10 0x00005555557cd310 in PyParser_ASTFromFileObject (fp=<optimized out>, filename=0x7ffff7778530,
    enc=<optimized out>, start=<optimized out>, ps1=<optimized out>, ps2=<optimized out>,
    flags=0x7fffffffd860, errcode=0x7fffffffd784, arena=0x7ffff783e390)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Python/pythonrun.c:1222
#11 0x0000555555640ee6 in PyRun_InteractiveOneObjectEx (fp=0x7ffff7defa00 <_IO_2_1_stdin_>,
    filename=0x7ffff7778530, flags=0x7fffffffd860)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Python/pythonrun.c:236
#12 0x00005555556411cc in PyRun_InteractiveLoopFlags (fp=0x7ffff7defa00 <_IO_2_1_stdin_>,
    filename_str=<optimized out>, flags=0x7fffffffd860)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Python/pythonrun.c:120
#13 0x00005555557cd85e in PyRun_AnyFileExFlags (fp=0x7ffff7defa00 <_IO_2_1_stdin_>,
    filename=0x5555557ce4b8 "<stdin>", closeit=0, flags=0x7fffffffd860)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Python/pythonrun.c:78
#14 0x00005555557cdbdc in pymain_run_file (p_cf=0x7fffffffd860, filename=<optimized out>,
    fp=0x7ffff7defa00 <_IO_2_1_stdin_>)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Modules/main.c:462
#15 pymain_run_filename (cf=0x7fffffffd860, pymain=0x7fffffffd970)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Modules/main.c:1655
#16 pymain_run_python (pymain=0x7fffffffd970)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Modules/main.c:2916
#17 pymain_main (pymain=0x7fffffffd970)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Modules/main.c:3456
#18 0x00005555557cdd2c in _Py_UnixMain (argc=<optimized out>, argv=<optimized out>)
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Modules/main.c:3491
#19 0x00007ffff7c5809b in __libc_start_main (main=0x555555641820 <main>, argc=1, argv=0x7fffffffdac8,
--Type <RET> for more, q to quit, c to continue without paging--
    init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdab8)
    at ../csu/libc-start.c:308
#20 0x0000555555733be9 in _start ()
    at /home/sat_bot/base/conda-bld/python_1631149597897/work/Parser/parser.c:325
(gdb)

所有这些信息中有什么有用的线索吗?

编辑 2

如果我以 root 身份启动 shell,则不存在此问题:

# python3.7
Python 3.7.11 (default, Sep  9 2021, 02:06:38)
[GCC 9.3.0] :: Intel Corporation on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
Traceback (most recent call last):
  File "/root/.startup.py", line 16, in <module>
    import readline
ImportError: /opt/intel/oneapi/intelpython/python3.7/lib/python3.7/site-packages/readline.cpython-37m-x86_64-linux-gnu.so: undefined symbol: tputs
>>> a=1
>>> a=np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>

编辑 3

我一直在研究这个问题。

如果我这样做,就像建议的那样:

$ sudo python3.7
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a=range(10)
>>> a
range(0, 10)
>>>

然后,我没有错误,但来自~/.startup.py 的所有库:

print("(.startup.py)")
import numpy as np
print("(imported numpy as np)")
import matplotlib.pyplot as plt
print("(imported matplotlib.pyplot as plt)")
from scipy.interpolate import CubicSpline
print("(imported scipy.interpolate CubicSpline)")
from scipy.interpolate import interp1d
print("(imported scipy.interpolate interp1d)")
import atexit
print("(imported os)")
import os
print("(imported sys)")
import sys
import readline
import rlcompleter
print("(imported glob)")
import glob
print("(imported re)")
import re

不可用。

我认为冲突来自这样一个事实,即使用$ sudo pthon3.7,我将二进制文件称为/usr/bin/python3.7 而不是/opt/intel/oneapi/intelpython/python3.7/bin/python3.7

如何区分这两个版本?或者我该如何避免两者之间的冲突?

我还提到了/opt/intel/oneapi/intelpython/python3.7/bin/python3.7,python shell 显示:

Python 3.7.11 (default, Sep  9 2021, 02:06:38)
[GCC 9.3.0] :: Intel Corporation on linux

这意味着 GCC-9.3.0 已安装在我的系统上,但实际上并非如此:也许这个 Intel python 需要一个基本上没有安装的gcc-9.3

这是一首好歌吗?

【问题讨论】:

我们需要检查二进制文件,将系统上的 libc 和其他库与编译时所针对的库进行比较,等等。 也就是说,您可以自己收集更多信息的方法是在 gdb 下运行它并收集堆栈跟踪。 尝试删除(或重命名)PYSTARTUP 环境变量。 一般来说,使用 3rd-party 二进制文件并不是一个好主意。 Intel 版本的性能可能会更好,但为了可靠性和兼容性,我会坚持使用由 Linux 发行版编译的 Python 运行时,或者至少在 在相同版本的 Linux 发行版上编译,针对它附带并经过测试的相同库。 (一个例外是使用像 Nix 这样的 3rd-party 包管理器,因为它提供了一个完整的依赖生态系统到 libc,并编译了 rpaths 以确保它提供的库被实际使用)。 当你以root身份运行时它工作并不一定意味着存在安装问题。出于安全原因,使用sudo 会清除许多环境变量,包括 LD_LIBRARY_PATHLD_PRELOAD(并且出于安全原因,还会忽略一些其他变量)。因此,它很可能是由 root 帐户不存在的设置触发的用户环境问题。 【参考方案1】:

当您为 oneAPI(或 intel python)获取 setvars 时,intel python 可执行文件被添加到当前用户的系统路径中。

路径变量将是特定于您的当前用户的环境变量。因此,当您使用 sudo 执行命令时,不会考虑环境变量,这就是您使用和不使用 sudo 执行 2 个不同的 python 可执行文件的原因。

您可以使用以下命令验证这一点

sudo which python
which python

如果您需要使用与 sudo 和普通用户相同的 python 可执行文件,运行 sudo -E python 以启动 shell 以拥有与普通用户相同的二进制文件。 (-E 保留环境变量)

python 解释器输出中的 gcc 版本只是指用于构建 python 二进制文件的 gcc 版本。和你安装的gcc没有关系。

您的查询中的错误可能是由于您的 pip 环境中的用户包可能彼此不兼容。您能否使用 intel python 创建一个新环境,如果您安装了 anaconda,我建议您使用 conda 并检查是否仍然出现错误。如果您仍然面临问题,请告诉我。 PFB 一个指导安装过程的链接。

https://software.intel.com/content/www/us/en/develop/articles/using-intel-distribution-for-python-with-anaconda.html

【讨论】:

以上是关于启动 Intel python3.7 shell 时出现意外错误:无法执行任何命令 - 中止错误的主要内容,如果未能解决你的问题,请参考以下文章

python3.7 os模块

ansible2.7 python3.7 redhat6.8

使用python3.7 的pycharm selenium自动化测试中启动360浏览器360极速浏览器的方法

windows10 Python2和Python3共存

模拟Python shell的“返回值”行为

如何启动Intel VT-x