Skip to main content
 首页 » 编程设计

python之pyinstaller 与 matlab : ImportError No module named 'mlarray'

2025年02月15日7lautakyan007

我正在尝试使用 pyinstaller 打包我的脚本。我的脚本与 matlab 交互,因此导入了 matlab python API。运行可执行文件时出现以下错误。


ImportError No module named 'mlarray'

问题出在导入 mlarray 模块上,所以我在一个最简单的脚本上做了一个实验,如下所示。

from matlab import mlarray 

然后,我用pyinstaller打包它。我得到了与预期相同的错误。 enter image description here

有人遇到过和我一样的问题吗?

请您参考如下方法:

我通过修改解决了

来自

from _internal.mlarray_sequence import _MLArrayMetaClass 

到

from matlab._internal.mlarray_sequence import _MLArrayMetaClass 

在 \Python36\Lib\site-packages\matlab\mlarray.py

和

来自

from _internal.mlarray_utils import _get_strides, _get_size, \ 
    _normalize_size, _get_mlsize, _reshape 

到

from matlab._internal.mlarray_utils import _get_strides, _get_size, \ 
    _normalize_size, _get_mlsize, _reshape 

在 \Python36\Lib\site-packages\matlab_internal\mlarray_sequence.py

并将 hiddenimports=['scipy._lib.messagestream'] 添加到规范文件中