MATLAB在Linux上尝试导入Python modu时崩溃

2024-06-16 09:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

{}每次使用Python从cdi>导入模块时都会崩溃。有时崩溃是立即的,但其他时候,它挂了一段时间前崩溃。有些模块似乎可以工作,例如py.importlib.import_module('math')工作正常,但是py.importlib.import_module('random')会导致崩溃。我也无法导入自定义模块。你知道吗

这是pyversion的输出:

>> pyversion

       version: '3.7'
    executable: '/home/garden/anaconda3/bin/python3'
       library: '/home/garden/anaconda3/lib/libpython3.7m.so'
          home: '/home/garden/anaconda3'
      isloaded: 0

有没有办法解决这个问题?你知道吗

我不确定这是否有用,但我已将其缩小到导致崩溃的特定行,即hashlib模块中的第244行:

240 for __func_name in __always_supported:
241     # try them all, some may not work due to the OpenSSL
242     # version not supporting that algorithm.
243     try:
244         globals()[__func_name] = __get_hash(__func_name)
245    except ValueError:
246         import logging
247         logging.exception('code for hash %s was not found.', __func_name)

Tags: 模块namepyimporthomeforversionnot
1条回答
网友
1楼 · 发布于 2024-06-16 09:30:55

根据MathWorks的支持,当Python试图使用MathWorks版本的libcrypto时,有时会出现这个问题。这可以通过在尝试导入其他模块之前使用Python加载SSL来解决。将这些行添加到MATLAB脚本的开头似乎可以解决我的问题:

py.sys.setdlopenflags(int32(10))
py.importlib.import_module('ssl')

相关问题 更多 >