【发布时间】:2017-05-31 09:13:52
【问题描述】:
我正在尝试构建我的 Python 应用程序的 .exe 文件。我尝试了各种方法从 Github 和 Stackoverflow 创建安装文件,但我不断收到同样的错误:
pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.').
我正在使用 Python 3.6.1 和 cx_Freeze 来构建应用程序。
以下是我尝试过的不同设置文件:
尝试 1:
import os.path
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
executables = [Executable("myprogram.py", base="Win32GUI")]
options = {
'build_exe': {
'include_files': [
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
]
},
}
setup(
name="Standalone.exe",
options=options,
version="0.1",
description='Simple tkinter application',
executables=executables, requires=['cx_Freeze', 'cx_Freeze']
)
尝试 2:
from cx_Freeze import setup, Executable
import sys
import os
productName = "My Program"
if 'bdist_msi' in sys.argv:
sys.argv += ['--initial-target-dir', r'C:\Users\RedCode\PycharmProjects\Standalone' + productName]
sys.argv += ['--install-script', 'myprogram.py']
os.environ['TCL_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
exe = Executable(
script="myprogram.py",
base="Win32GUI",
targetName="Product.exe"
)
setup(
name="Standalone.exe",
version="1.0",
author="Me",
description="Copyright 2012",
executables=[exe],
scripts=[
'myprogram.py'
]
)
尝试 3:
import sys
import os
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "includes": ["tkinter"]}
def s_SourceFile():
if (sys.argv[0] == ''):
return __file__
else:
return sys.argv[0]
os.environ['TCL_LIBRARY'] = r'C:\Users\stefano.demattia\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\stefano.demattia\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6'
setup(name="Standalone",
version="0.1",
description="My GUI application!",
options={"build_exe": build_exe_options},
executables=[Executable("myprogram.py", base="Win32GUI", targetName="Standalone.exe")])
尝试 4:
application_title = "Car Database"
main_python_file = "cardb.py"
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "myprogram.py",
version = "0.1",
description = "Simple embedded database application",
executables = [Executable("myprogram.py", base = base)])
我也尝试过 pyinstaller,但无论我做什么,它都会给我一个元组超出范围的错误,我尝试了 bbfreeze,我什至无法安装。我检查了我的文件,一切都在那里,所以我看不出它如何仍然告诉我找不到指定的文件。
我还能做什么或如何编辑上述尝试以使应用程序真正正确构建?有没有办法确定哪个文件丢失了?
【问题讨论】:
-
是在冻结期间还是在您尝试运行冻结的应用程序时出现错误?无论哪种方式,请发布完整的错误消息。
-
我不从 python 终端运行它。我只是打开一个常规的命令提示符。然后我对我的 .py 文件的存储方向执行“cd”。因此,例如我会执行 'cd C:\Users\gardener\PycharmProjects\untitled5\' 然后我会输入 'python setup.py build'
标签: python-3.x build cx-freeze setup.py