gpt4 book ai didi

python - 卡住 (.exe) 一个 traitsUI 程序,现实可行吗?

转载 作者:行者123 更新时间:2023-11-28 18:39:36 24 4
gpt4 key购买 nike

我正在尝试使用 cx_freeze 或 pyInstaller 卡住一个 TraitsUI 程序,该程序使用了 Chaco、Traits、TraitsUI 和较小程度的 mayavi(实际上可以被删除)。我需要它在 mac、linux、ubuntu 上运行,所以我避免使用 py2exe。 我特意卸载了 pyqt 和 pyside,以便只有 wx 后端可用。

在使用 cx_freeze 时,我遇到并报告了一个错误,因此 pyInstaller 似乎让我受益匪浅。它生成了一个 .exe 文件,但是当我运行该文件时,我收到警告和错误。要生成我所做的 .exe 文件:

pyinstaller --onefile --name=pameapp pamemain.py 
pyinstaller pameapp.exe

运行时,警告是:

Warning: Unable to import the wx backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named wx.init

Warning: Unable to import the qt4 backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named init

Warning: Unable to import the null backend for pyface due to traceback: Traceback (most recent call last):
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 45, in _init_toolkit
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/pyface.toolkit", line 31, in import_toolkit
ImportError: No module named null.init

此外,我收到以下错误:

Traceback (most recent call last):
File "<string>", line 8, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.api", line 35, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors", line 22, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.api", line 10, in <module>
File "/home/glue/anaconda/envs/fibersim/lib/python2.7/site-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 36, in <module>
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.editors.code_editor", line 48, in ToolkitEditorFactory
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 487, in __call__
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traits.traits", line 1191, in Color
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit_traits", line 7, in ColorTrait
File "/home/glue/Desktop/fibersim/pame/build/pameapp/out00-PYZ.pyz/traitsui.toolkit", line 137, in toolkit
traits.trait_errors.TraitError: Could not find any UI toolkit called 'null'

pyface大概有很多动态导入,所以这一定是任何试图卡住ETS的人都会遇到的问题。是否有一个单一的修复方法可以使它正常工作?

考虑到网络上流传的有关卡住 ETS 计划的成功率的旧资料,是否值得进一步投资?对我们来说,让人们避免为这个应用程序配置 python 将是一个巨大的优势。

谢谢。

最佳答案

您使用的 Pyface.toolkit 正在使用动态导入:

def import_toolkit(tk):
try:
# Try and import the toolkit's pyface backend init module.
be = 'pyface.ui.%s.' % tk
__import__(be + 'init')
except:
raise
return be

因此 pyinstaller 无法检测到这一点。使用 python -v b.py 2>&1 | 检查grep imp 什么是特定的导入和添加 Hook 文件 (hook-.py) 以及适当的 hiddenimports 列表。

但是我在本地做了一些测试,我无法使用 __import__ 进行工作测试模式。这很奇怪,因为我做了一些调试,我发现添加了 hiddenimport 但仍然无法使用。

关于python - 卡住 (.exe) 一个 traitsUI 程序,现实可行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28079792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com