简体   繁体   English

使用cx_freeze将.py转换为可执行文件时出错

[英]Error converting .py to executable using cx_freeze

I am using python 3.3.3 我正在使用python 3.3.3

the following is my setup.py code 以下是我的setup.py代码

    import sys
from cx_Freeze import setup, Executable


build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "send_email",
        version = "0.1",
        description = "send the email",
        options = {"build_exe": build_exe_options},
        executables = [Executable("send_email.py", icon="icon.ico", base=base)])  

The only import in my send_email.py file is smtplib. 我的send_email.py文件中唯一的导入是smtplib。

The following error message is what I receive when building the executable in the command window: 以下错误消息是在命令窗口中构建可执行文件时收到的消息:

c:\Python33>python.exe setup.py build
running build
running build_exe
copying c:\Python33\lib\site-packages\cx_Freeze\bases\Win32GUI.exe -> build\exe.
win-amd64-3.3\send_email.exe
copying C:\Windows\SYSTEM32\python33.dll -> build\exe.win-amd64-3.3\python33.dll

Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    executables = [Executable("send_email.py", icon="icon.ico", base=base)])
  File "c:\Python33\lib\site-packages\cx_Freeze\dist.py", line 365, in setup
    distutils.core.setup(**attrs)
  File "c:\Python33\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "c:\Python33\lib\distutils\dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "c:\Python33\lib\distutils\dist.py", line 936, in run_command
    cmd_obj.run()
  File "c:\Python33\lib\distutils\command\build.py", line 126, in run
    self.run_command(cmd_name)
  File "c:\Python33\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "c:\Python33\lib\distutils\dist.py", line 936, in run_command
    cmd_obj.run()
  File "c:\Python33\lib\site-packages\cx_Freeze\dist.py", line 235, in run
    freezer.Freeze()
  File "c:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 577, in Freeze

    self._FreezeExecutable(executable)
  File "c:\Python33\lib\site-packages\cx_Freeze\freezer.py", line 169, in _Freez
eExecutable
    cx_Freeze.util.AddIcon(exe.targetName, exe.icon)
SystemError: error return without exception set

I had the same message error and I fixed it by giving the full path of the icon file. 我遇到了相同的消息错误,并通过提供图标文件的完整路径来修复它。 By the way, make sure the icon is in .ico format (At first I renamed the extensions of a .png file to .ico and caused the process to crash, lastly I converted the .png file to the .ico format and it worked). 顺便说一句,确保图标为.ico格式(起初,我将.png文件的扩展名重命名为.ico并导致进程崩溃,最后我将.png文件转换为.ico格式,并且可以正常工作)。

use this setup file . 使用此安装文件。

from cx_Freeze import setup, Executable

GUI2Exe_Target_1 = Executable(
    script = "Your scripts",
    initScript = None,
    base = 'Win32GUI',
    targetName = "app.exe",
    compress = True,
    copyDependentFiles = True,
    appendScriptToExe = False,
    appendScriptToLibrary = False,
    icon = "YOUR ICON FILE.ico"
    ) 
excludes = ["pywin", "tcl", "pywin.debugger", "pywin.debugger.dbgcon",
        "pywin.dialogs", "pywin.dialogs.list", "win32com.server",
        "email"] 
includes = ["PyQt4.QtCore","PyQt4.QtGui","win32gui","win32com","win32api","html.parser","sys","threading","datetime","time","urllib.request","re","queue","os"] 
packages = [] 
path = [] 
setup(
    version = "1.0",
    description = "myapp",
    author = "me",
    author_email = "email@email.com",
    name = "Your app name !",
    options = {"build_exe": {"includes": includes,
                             "excludes": excludes,
                             "packages": packages,
                             "path": path
                            }
               },
    executables = [GUI2Exe_Target_1]
    )

I had the SAME EXACT ERROR that i just fixed right now! 我有一个完全一样的错误,我现在就解决了! There is a very simple solution , you are getting this error becasue of your icon file. 有一个非常简单的解决方案,由于图标文件,您将收到此错误。

  1. I take it you have a setup.py file with something along the lines of executables = [cx_Freeze.Executable("filename.py", base=base, icon="youricon")] 我认为您有一个setup.py文件,其中包含一些executables = [cx_Freeze.Executable("filename.py", base=base, icon="youricon")]

You need to make sure that your icon is an .ico file. 您需要确保您的图标是.ico文件。 Simply search for .gif or .png to .ico converter and it will do it for you! 只需搜索.gif或.png到.ico转换器,它将帮您实现!

Make sure also that your .ico file is inside your folder of your files. 还请确保您的.ico文件位于文件文件夹中。 Make sure to include files in the options 确保在选项中包含文件

You probably have something else in your setup.py along the lines of... 您的setup.py中可能还包含其他内容...

options = {"build_exe":{"packages":["THEMODS YOU IMPORTED HERE"],"include_files":["THE FILES NEED TO BE HERE"]}

This is what fixed the problem for me. 这就是为我解决问题的原因。 LMK if this helps :) LMK如果有帮助的话:)

将选项更改为:

build_exe_options = {"packages": ["os"], "excludes": ["tkinter"],"include_files": ["icon.ico"],}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM