d3.js - 使用 pyinstaller 和 Matlab 引擎创建 .exe 文件

标签 d3.js python-3.x matlab pyinstaller matlab-engine

我已经使用 pyqt 制作了一个应用程序。从 IDE 运行时,.py 文件运行良好。但是,当使用以下命令运行 .exe 文件时:

pyinstaller --name="Myapp" --windowed --onefile main.py

我得到一个 .exe 文件。当我尝试运行它时,它说

Failed to execure script main

我又试了一次,但这次是:

pyinstaller main.py

它确实在 dist 中生成了一个名为 main 的文件夹。我在命令行中运行 main.exe 并得到:

ImportError: No module named 'mlarray'

我转到安装在 \Python\Python36\Lib\site-packages\matlab 中的 python 的 matlab 库并更改了 mlarray.py 如下: 来自

from _internal.mlarray_sequence import _MLArrayMetaClass

收件人:

from matlab._internal.mlarray_sequence import _MLArrayMetaClass

我什至更改了 __init__.py: 来自:

from mlarray import double, single, uint8, int8, uint16, \
    int16, uint32, int32, uint64, int64, logical
from mlexceptions import ShapeError as ShapeError
from mlexceptions import SizeError as SizeError

到:

from matlab.mlarray import double, single, uint8, int8, uint16, \
    int16, uint32, int32, uint64, int64, logical
from matlab.mlexceptions import ShapeError as ShapeError
from matlab.mlexceptions import SizeError as SizeError

最后我更改了 Python\Python36\Lib\site-packages\matlab\_internal\mlarray_sequence.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

保存所有工作并再次尝试执行 pyinstaller。

pyinstaller main.py

这次我得到以下错误:

  File "site-packages\matlab\engine\__init__.py", line 62, in <module>
OSError: Please reinstall MATLAB Engine for Python or contact MathWorks Technical Support for assistance: [Errno 2] No such file or directory: 'C:\\pmafgx_das\\das2\\main\\ReleaserQt\\dist\\main\\matlab\\engine\\_arch.txt'
[2028] Failed to execute script main

我越来越沮丧,我不知道还能做什么。如果您有任何见解,请帮助我。

最佳答案

首先删除对 matlab 的更改。

然后创建一个目录结构 - 和 hook-matlab.py 文件 - 就像下面的树:

- script_to_compile.py  # This is the python file you run pyinstaller on
- hooks  # DIR
  - hook-matlab.py

hook-matlab.py 内部:

from PyInstaller.utils.hooks import collect_all

datas, binaries, hiddenimports = collect_all('matlab')

然后使用额外选项 --additional-hooks-dir=hooks 进行构建。

关于d3.js - 使用 pyinstaller 和 Matlab 引擎创建 .exe 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61482776/

相关文章:

Python:创建一个字典,其中的键有多个值

matlab - 使用隐马尔可夫模型的手势识别

matlab - 函数之外的 nargin 是什么?

javascript - D3 中的图例标题

animation - 如何为D3面积图的区域设置动画?

javascript - D3 数据未更新

python - 使用python3从风格为列表和元组的txt文件中获取信息

python - mysql的高吞吐量,安全插入?

javascript - Babel 中的 d3 事件回调上下文发生变化

Matlab的cellfun不按特定顺序执行对函数func的调用?