我试图从python2.7编写的程序中创建一个exe文件(使用GTK+布局)。我查阅了本指南:http://www.py2exe.org/index.cgi/Py2exeAndPyGTK,并尝试相应地设置我的文件。我成功地生成了一个.exe文件,但在尝试运行它时,我遇到了以下错误:
Traceback (most recent call last):
File "cipherka.py", line 183, in <module>
File "cipherka.py", line 18, in __init__
GError: Nelze otevřít soubor "C:\Repa\cipherka\dist\library.zip\gui.xml": No such file or directory
当我找不到图形用户界面.xml文件图书馆.zip存档,它与main.exe在同一级别上可用(西弗卡.exe)文件。如果我自己把它复制到.zip文件中,它并不能解决问题。在
这是我的设置.py文件:
^{pr2}$任何帮助都将得到广泛的感谢!我可以在需要的时候给你任何必要的信息。泰铢
好吧,我实现了改变。但是,它做了一些奇怪的事情。当我使用:
path = os.path.dirname(__file__).replace('\\library.zip','')
它在从.py文件运行时正常,但在编译时失败,并出现以下错误:
Traceback (most recent call last):
File "cipherka.py", line 217, in <module>
File "cipherka.py", line 18, in __init__
NameError: global name '__file__' is not defined
当我使用
path = os.path.dirname('gui.xml').replace('\\library.zip','')
相反,程序停止从python运行,编译后的版本给出了以下信息:
C:\Repa\cipherka\dist\cipherka.exe:188: GtkWarning: gtk_tree_path_append_index: assertion `index >= 0' failed
C:\Repa\cipherka\dist\cipherka.exe:188: GtkWarning: gtk_tree_model_get_iter: assertion `path->depth > 0' failed
Traceback (most recent call last):
File "cipherka.py", line 217, in <module>
File "cipherka.py", line 55, in __init__
File "cipherka.py", line 188, in changed_cb
IndexError: could not find tree path
有什么想法吗?在
"gui.xml"
在"C:\Repa\cipherka\dist\"
中,而不是您的代码假定的"C:\Repa\cipherka\dist\library.zip"
。在不管你的程序是不是编译的,这都应该有效。在
报告的错误是由于在
py2exe
下运行的脚本没有__file__
全局。检测到这一点并在.py
文件中使用sys.argv[0]
。在相关问题 更多 >
编程相关推荐