d3.js - 使用 pyinstaller 和 Matlab 引擎创建 .exe 文件
问题描述
我已经使用pyqt
. 从 IDE 运行时,.py 文件运行良好。但是,当使用以下命令运行 .exe 文件时:
pyinstaller --name="Myapp" --windowed --onefile main.py
我得到一个 .exe 文件。当我尝试运行它时,它说
Failed to execure script main
我又试了一次,但这次是:
pyinstaller main.py
它确实生成了一个名为main
in的文件夹dist
。我main.exe
在命令行中运行,我得到:
ImportError: No module named 'mlarray'
我去了matlab
我安装的python库\Python\Python36\Lib\site-packages\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
它变得非常令人沮丧,我不知道该怎么做。请如果你有一个见解,如果你能帮助我,我会appritiate。
解决方案
首先删除对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
。
推荐阅读
- redis - zrevrange 具有相同分数的成员的顺序不颠倒
- graphql - 基于许多内容引用使用 Gatsby 动态创建页面
- reactjs - react redux 中的调度类型使用
- java - 使用连接池的多个数据库连接与使用多个语句的单个连接
- algorithm - 谁能解释 CodeChef 中的隐藏序列问题?
- android - Jetpack Compose 视图中的提前返回会因“java.lang.IllegalStateException:开始/结束不平衡”而崩溃?
- python - 如何使用 OOP 编程修复方法中的错误
- php - 试图在 PHP 中获取 rethinkdb 实例的状态
- php - PHP reg 表达式检测字符串中的变量
- python - Python 内存分析