带有 VTK 的 Python 可执行文件... pyinstaller、py2exe、cx_freeze 等 [英] Python executable with VTK... pyinstaller, py2exe, cx_freeze etc

查看:88
本文介绍了带有 VTK 的 Python 可执行文件... pyinstaller、py2exe、cx_freeze 等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pyqt 在 python 中构建了一个 gui,它导入了 VTK.我没有任何运气让 py2exe、pyinstaller cx_freeze 等使用它......我使用 pyinstaller 说出以下内容时出现错误:

I've built a gui in python using pyqt which imports VTK. I'm having no luck whatsoever getting py2exe, pyinstaller cx_freeze etc to work with it... I get an error saying something along the lines of the following using pyinstaller:

vtk.__helper.LinkError: No module named vtkFilteringPythonSIP

我已经设法使用 pyinstaller 制作了不包含 vtk 代码的可执行文件,所以我目前倾向于这样做,但是如果有人可以帮助我编写代码来实现这一点:http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt 代码作为可执行文件工作,那么我将永远感激,但它已经完成.我已经尝试将它抱怨的文件添加到 pyinstaller 挂钩,但仍然没有运气.是否有修复此错误的旧/开发版本?在信息高速公路上找不到任何解决方案,尽管我在同一条船上找到了人.我正在使用最新版本的 Python (X,Y).

I have managed to make working executables that don't contain vtk code with pyinstaller so I'm leaning towards that at the moment, but if someone can help me write code which will make this: http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt code work as an executable then I will be eternally grateful, however it is done. I've tried adding the files it complains about to the pyinstaller hooks but still no luck. Is there an old/ development version that has fixed this bug? Can't find any solutions on the information super highway although I have found people in the same boat. I'm using the latest version of Python (X,Y).

推荐答案

如果有人遇到同样的问题,我设法通过执行以下操作使我的代码正常工作:

If anybody stumbles across this having had the same problem, I managed to get my code working by doing the following:

  • 在 pyinstaller hooks 文件夹中,将hook-vtkpython.py"重命名为hook-vtk.py"

然后我在运行 pyinstaller 生成的可执行文件时遇到了一个不同的错误,关于无法找到名为 QtOpenGL 的模块.这发生在名为 __helper.py 的站点包中 vtk 文件夹中的文件中.我只是注释掉了最后两行以去除它的牙齿.

I then got a different error when running the executable generated by pyinstaller about not being able to find a module called QtOpenGL. This was happening inside a file in the vtk folder in site-packages called __helper.py. I simply commented out the last two lines to remove its teeth.

我还更改了我的代码,这样我就不再导入所有 vtk,而是导入了我需要的位.不确定是否只有第一步或两个步骤才能解决我担心的问题,但他们/它确实解决了.问题出在 Python (x,y) 2.7.5.1 上.您的里程可能会有所不同.

I also changed my code so that rather than importing all of vtk I just imported the bits I needed. Not sure if just the first or both of these steps were necessary to solve the problem I'm afraid, but solve it they/it did. The problem was happening with Python (x,y) 2.7.5.1. Your mileage may vary.

这篇关于带有 VTK 的 Python 可执行文件... pyinstaller、py2exe、cx_freeze 等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆