gpt4 book ai didi

Python cx_freeze 4.3.4 : Setting targetName causes errors

转载 作者:行者123 更新时间:2023-11-28 20:43:39 25 4
gpt4 key购买 nike

我是 cx_freeze 的新手,我想更好地理解它,我有这个 setup.py 文件:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

setup( name = "guifoo",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("mypy.py", base="Console", targetName="hello")])

如果我删除 targetName="hello"它会起作用,但是当我包含它时,它不会。有人知道为什么吗?

这是我的 python 代码:

# encoding: utf8
import math
print "Starting..."
print math.sqrt(16)
input("please press enter to exit...")

运行 python setup.py build 后出现以下错误:

running build
running build_exe
creating directory build\exe.win32-2.7
copying C:\Python27\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win32-2.7\hello
copying C:\Windows\system32\python27.dll -> build\exe.win32-2.7\python27.dll
Traceback (most recent call last):
File "setup.py", line 11, in <module>
executables = [Executable("mypy.py", base="Console", targetName="hello")])
File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 362, in setup
distutils.core.setup(**attrs)
File "C:\Python27\lib\distutils\core.py", line 151, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\distutils\command\build.py", line 127, in run
self.run_command(cmd_name)
File "C:\Python27\lib\distutils\cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\cx_Freeze\dist.py", line 232, in run
freezer.Freeze()
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
self._FreezeExecutable(executable)
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 211, in _FreezeExecutable
self._AddVersionResource(exe.targetName)
File "C:\Python27\lib\site-packages\cx_Freeze\freezer.py", line 150, in _AddVersionResource
stamp(fileName, versionInfo)
File "C:\Python27\lib\site-packages\win32\lib\win32verstamp.py", line 159, in stamp
h = BeginUpdateResource(pathname, 0)
pywintypes.error: (2, 'BeginUpdateResource', 'The system cannot find the file specified.')

在目标名称处添加一个 .exe 确实解决了这个问题

最佳答案

重新发布作为答案:

targetName 是它要生成的可执行文件的文件名。在 Windows 上,可执行文件必须具有 .exe 扩展名,因此您需要将其设置为 'hello.exe' 而不仅仅是 'hello'

关于Python cx_freeze 4.3.4 : Setting targetName causes errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28542541/

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