我已经使用 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/