我正在 Python 上开发一个小工具,它基本上在文件夹上启动一组脚本。我需要将它打包在一个独立的二进制文件中,并且我正在使用 py2exe。
我当前的代码用于os.path.listdir()
获取文件夹中的所有 .py 文件,然后使用execfile()
基于 PyQT 界面上的用户输入的函数启动其中的一些文件。
如果通过主 Python 文件执行,我的代码按预期工作,但在使用 py2exe 编译时失败。例外是:
IOError: [Errno 2] No such file or directory
对于使用execfile()
.
我目前正在与"bundle_files": 1
and捆绑zipfile = None
。我试图包含这些与包含和包混淆的文件,但没有运气。你能帮我正确配置py2exe吗?
这是我目前的setup.py
:
from distutils.core import setup
import py2exe
import os
#Python modules excluded from binary file
mod_excludes = [
"Tkinter",
"doctest",
"unittest",
"pydoc",
"pygments",
"pdb",
"email",
"_ssl",
"difflib",
"inspect"
]
#Avoid adding this dependencies
dll_excludes = [
"MSVCP90.dll",
"w9xpopen.exe"
]
#Force to exe
mod_includes = [
"sip"
]
package_includes = [
"app.payloads"
]
py2exe_options = {
"optimize": 2, # 0 (None), 1 (-O), 2 (-OO)
"includes": mod_includes,
"excludes": mod_excludes,
"dll_excludes": dll_excludes,
"packages": package_includes,
#"xref": False,
"bundle_files": 1,
"compressed": True
#"dist_dir": dist_dir
}
#TODO generar automaticamente la interfaz
setup(
windows=[{"script": "app.py",
"icon_resources": [(1, "app/gui/Res/app.ico")],
"uac_info": "requireAdministrator"}],
data_files=exe_files,
options={"py2exe": py2exe_options},
zipfile=None
)
我得到以下回溯:
Traceback (most recent call last):
File "app\gui\ui.pyo", line 22, in call_report
File "app\core\core.pyo", line 32, in generate_report
File "app\core\core.pyo", line 18, in launch_payload
IOError: [Errno 2] No such file or directory: 'C:\\Users\\my_user\\path\\to\\app\\dist\\app.exe\\app\\payloads\\autoruns.py'