Python cx_freeze 4.3.4:设置targetName会导致错误 [英] Python cx_freeze 4.3.4: Setting targetName causes errors

查看:138
本文介绍了Python cx_freeze 4.3.4:设置targetName会导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对cx_freeze还是陌生的,我想更好地理解它,我有这个setup.py文件:

I am very new to cx_freeze and I am trying to understand it a bit better, I have this setup.py file:

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,它会起作用但是,当我包括它时,它没有。有人知道为什么吗?

which if I remove the targetName="hello" it works however when I include it, it doesnt. Would anyone know why?

这是我的python代码:

This is my python code:

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

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

After running python setup.py build I get the following errors:

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可以解决此问题

Adding a .exe at the target name does resolve this

推荐答案

重新发布作为答案:

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

targetName is the filename of the executable it's going to produce. On Windows, executables must have a .exe extension, so you'll need to set it as 'hello.exe' rather than just 'hello'.

这篇关于Python cx_freeze 4.3.4:设置targetName会导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆