Pyinstaller 和 Pymeshlab

Pyinstaller and Pymeshlab

我正在尝试让 Pyinstaller 与使用 pymeshlab 的程序一起工作。下面是一个示例 python 脚本 (main.py),它使用了我想要的函数:

import pymeshlab
import numpy as np

mesh_a_verts = np.array([[0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [0., 1., 1.], [1., 0., 0.],
                         [1., 0., 1.], [1., 1., 0.], [1., 1., 1.], [0., 0.5, 0.5], [1., 0.5, 0.5]])

mesh_a_faces = np.array([[0, 8, 2], [2, 8, 3], [3, 8, 1], [1, 8, 0], [6, 9, 4], [7, 9, 6], [5, 9, 7],
                         [4, 9, 5], [2, 6, 4], [2, 4, 0], [3, 7, 6], [3, 6, 2], [1, 5, 7], [1, 7, 3], [0, 4, 5],
                         [0, 5, 1]], )

mesh_b_verts = np.array([[0.5, 0., 0.], [0.5, 0., 1.], [0.5, 1., 0.], [0.5, 1., 1.], [1.5, 0., 0.],
                         [1.5, 0., 1.], [1.5, 1., 0.], [1.5, 1., 1.], [0.5, 0.5, 0.5]])

mesh_b_faces = np.array([[0, 8, 2], [2, 8, 3], [3, 8, 1], [1, 8, 0], [7, 5, 4], [6, 7, 4], [2, 6, 4],
                         [2, 4, 0], [3, 7, 6], [3, 6, 2], [1, 5, 7], [1, 7, 3], [0, 4, 5], [0, 5, 1]])


def main():
    ms = pymeshlab.MeshSet()
    ms.add_mesh(pymeshlab.Mesh(mesh_a_verts, mesh_a_faces))
    ms.add_mesh(pymeshlab.Mesh(mesh_b_verts, mesh_b_faces))

    ms.generate_boolean_intersection(first_mesh=0, second_mesh=1)

    print(ms.mesh(2).vertex_matrix(), ms.mesh(2).face_matrix())


if __name__ == '__main__':
    main()

这个 运行 在 python 中很好,但是当我尝试将它与 Pyinstaller 和 运行 生成的可执行文件捆绑在一起时,我收到错误:

Traceback (most recent call last):
  File "main.py", line 29, in <module>
  File "main.py", line 23, in main
AttributeError: 'pymeshlab.pmeshlab.MeshSet' object has no attribute 'generate_boolean_intersection'
[27580] Failed to execute script 'main' due to unhandled exception!

我想也许 Pyinstaller 缺少一些 dll,所以我在我的 main.spec 中添加了以下内容,但它没有帮助

from pathlib import Path
import pymeshlab
from os import listdir

pmeshlab_plugins_path = Path(pymeshlab.__file__).parent / "lib" / "plugins"
pm_binaries = [(pmeshlab_plugins_path/plugin, "./pymeshlab/lib/plugins") for plugin in listdir(pmeshlab_plugins_path)]



block_cipher = None


a = Analysis(['main.py'],
             pathex=[],
             binaries=[*pm_binaries],

...

有什么想法吗?

pyinstaller 选项 --collect-all=pymeshlab 对我有用。这会将指定包中的所有内容复制到 pyinstaller 输出中,因此一定复制了我遗漏的内容。