【发布时间】:2013-11-22 10:49:06
【问题描述】:
我正在尝试使用 PyInstaller(单文件模式)创建一个 exe 文件。 我的程序是单个文件(usingTry.py)。这是一个超级简单的文件,它从我创建的 egg 文件中实例化了一个名为“TrySystem”的类。 “TrySystem”类加载一个 XRC 文件并使用 wxPython 在其中放置一个位图按钮。 XRC 和图像文件保存为内蛋资源,如Managing resources in a Python project 中所述
我在 Mac (10.8.5) 上准备鸡蛋:
sudo python setup.py bdist_egg
然后我将它复制到 winXP 机器上(实际上它与 VM 在同一计算机上运行)并安装它:
easy_install Try\try2\dist\try3-1.0-py2.7.egg
当我尝试从 python 终端(在 WinXP 上)运行“python usingTry.py”时,一切正常,我看到了框架和按钮。 然后我继续从“usingTry.py”(在 WinXP 上)准备一个 exe 文件:
Try\users\usingTry>pyinstaller.py -F usingTry.py
然后我尝试运行它:
Try\users\usingTry>dist\usingTry.exe
Traceback (most recent call last):
File "<string>", line 11, in <module>
File "<string>", line 4, in __init__
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 35, in __init__
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 8, in __init__
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\wx._core", line 7981, in __init__
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\wx._core", line 7555, in _BootstrapApp
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\try3", line 14, in OnInit
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\pkg_resources", line 868, in resource_filename
File "z:\Documents\workspace\python\Try\users\usingTry\build\pyi.win32\usingTry\out00-PYZ.pyz\pkg_resources", line 181, in get_provider
File "c:\programs\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook
raise ImportError("No module named %s" % fqname)
ImportError: No module named try3.resources
有人知道如何解决这个问题吗? 在这个link 是一个包含所有内容的 zip 文件:
try.zip:
Try/
try2/ (this is the code that creates the egg)
setup.py
ez_setup.py
try3/ (the egg's code)
__init__.py
resources/ (here are the resource files used in the egg)
__init__.py
main.xrc
stopButton.png
build/
... (files created while I built the egg)
dist/
try3-1.0-py2.7.egg (the prepared egg file)
try3.egg-info/
...
users/
usingTry/ (here is the code that uses the egg file)
usingTry.py
usingTry.spec
dist/
usingTry.exe (created by "pyinstaller -F usingTry.py")
try3/ (I manually copied it here from Try/try2/ so the exe file works)
build/ (created by PyInstaller)
...
logdict2.7.5.final.0-1 (created by PyInstaller)
您会注意到文件夹 Try\try2\try3(包含 egg 的代码)被手动复制到创建的 exe 文件所在的位置 (Try\users\usingTry\dist)。那是因为它使 exe 文件工作。 我在PyInstaller generated exe not working, project uses ReportLab找到了这个解决方法
我想做的是避免这种变通方法,这样一切都会奏效。它必须非常简单,因为它在 PyInstaller 网站上声明他们完全支持使用 egg 文件。
【问题讨论】:
-
您可以做的一件实际上并不能解决问题的事情是将这些文件作为数据文件包含在内。它会为您将它们复制到 dist/ 目录。你想要的可能是直接从鸡蛋中访问文件,对吧?那个should be possible,我记得我曾经让它工作过。如果我来不及回答,请告诉我,我或许可以为您提供帮助。
-
是的,请!我仍在等待有人帮助我。
标签: python pyinstaller egg