2014-01-19 111 views
1

当我编译我的文件(snake.py)为exe,输出文件(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)]) 
+0

你用什么工具“编译”exe文件? – Fenikso

+0

exe给出了什么错误?它究竟如何“不起作用”? – Fenikso

+0

建立exe的设置是什么?你能成功构建“hello_world.py”吗?你能成功地构建“hello_qt.py”吗? – Fenikso

回答

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 

这应该做工精细。