pyinstaller打包相关问题

请问有开发者尝试过使用pyinstaller打包taichi程序并成功运行的吗,我在打包过程中遇到了一些问题。
打包的exe文件运行时出现:

OSError: could not get source code
ModuleNotFoundError: No module named ‘bpy_types’

github上曾经有人提过相关issue但最终并未解决
issue:Taichi doesn't compile to Pyinstaller · Issue #4936 · taichi-dev/taichi · GitHub

1 个赞

目前来看问题应该出在bpy上,这里我还是比较迷惑,因为直接python运行是没有问题的,甚至我在环境中都不需要主动去安装bpy,打包成exe后却提示找不到bpy,安装bpy之后bpy本身在导入的时候还存在问题 :joy:

找到了一个一年前的issue,大概和这个是同一个原因?

Taichi doesn’t support to be run from .pyc at this moment due to the fact that it needs to get the source of functions to work properly. In fact, Taichi uses the inspect module to extract the source of function @ti.kernel is decorated, then modify the source using ast module in order to translate Python syntax into Taichi API calls, then re-compile the modifed source into binary code (pyc) and run it.
NOTE: It might be possible to support Taichi in .pyc, that is to store the ‘modifed’ code object, but not sure it worth the complicity to do this change…

那么目前这个问题是否是无法解决的呢

1 个赞

Also, this post:

感谢您的回复,我在找问题的过程中为了避免不正确的操作,使用的就是官方文档中的Julia set示例程序,python运行正常,在解决了上述两个帖子的问题后,pyinstaller打包exe报上述和issue 4936相同的错误。