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

Unexpected error when Intel python3.7 shell is launched : impossible to do any command - abort error

在 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 基本上没有安装。

这首歌好听吗?

当您为 oneAPI(或英特尔 python)提供 setvars 时,英特尔 python 可执行文件会添加到 当前用户 的系统路径中。

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

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

sudo which python
which python

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

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

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

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