exe文件无法正常工作(没有任何反应)

时间:2014-01-19 17:10:07

标签: python python-3.x cx-freeze

当我将我的文件(snake.py)编译为exe时,输出文件(exe文件)不起作用。 我认为这可能是编译过程中出现错误的结果:

missing modules:
? _frozen_importlib imported from importlib

enter image description here

任何想法??

import sys
from cx_Freeze import setup, Executable

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

setup(
    name = "simple_PyQt4",
    version = "0.1",
    description = "Sample cx_Freeze PyQt4 script",
    options = {"build_exe" : {"includes" : "atexit" }},
    executables = [Executable("hello_qt.py", base = base)])

1 个答案:

答案 0 :(得分:1)

我使用PySide,但它应该几乎等同于你的PyQt。

我有这段代码hello_pyside.py

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Window(QWidget):
    def __init__(self, *args, **kwargs):
        QWidget.__init__(self, *args, **kwargs)

        self.button = QPushButton("Test", self)
        self.button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)

        self.layout = QHBoxLayout()
        self.layout.setContentsMargins(5, 5, 5, 5)
        self.layout.addWidget(self.button)

        self.setLayout(self.layout)
        self.show()

app = QApplication(sys.argv)
win = Window()
sys.exit(app.exec_())

我将此脚本称为cx_freeze

c:\Python33\Scripts\cxfreeze.bat hello_pyside.py --target-dir=Bin/pyside --base-name=Win32GUI --target-name=hello_pyside.exe --include-modules=re --exclude-modules=Tkinter

我得到的目录包含:

_bz2.pyd
hello_pyside.exe
PySide.QtCore.pyd
PySide.QtGui.pyd
pyside-python3.3.dll
python33.dll
QtCore4.dll
QtGui4.dll
shiboken-python3.3.dll
unicodedata.pyd

这应该可以正常工作。