2013-07-10 87 views
0

更新:cxFreeze如何包含內部項目模塊?

我懷疑這是在cxFreeze一個錯誤,因爲我知道這應該 自動進入。

末更新

更新:

我錯過了cxFreeze給出錯誤:

Missing modules: 
? Test.MyClass imported from main__main__ 

末更新

我不知道是什麼適當的術語是針對模塊內的項目不像sys或PyQt,所以我要使用內部項目模塊。

我有一些示例代碼,下面我收到錯誤「ImportError:無法導入名稱MyClass」。我很想知道如何讓cxFreeze編譯'Test.py'模塊。

這是我的主要代碼:

Main.py

import sys 
from PyQt5.QtWidgets import QApplication, QMainWindow 
#from guiObjects.MainWindow import MainWindow 
from Test import MyClass 

if __name__ == "__main__": 

    # Initializing the main window 
    app = QApplication(sys.argv) 
    widget = QMainWindow() 
    #mainWindow = MainWindow(widget) 
    test = MyClass() 
    widget.show() 

    sys.exit(app.exec_()) 

Test.py

class MyClass(object): 
    def __init__(self): 
     pass 

__init.py__

'''empty''' 

Setup.py

import sys 
from cx_Freeze import setup, Executable 

path_platforms = ("C:\Python33\Lib\site-packages\PyQt5\plugins\platforms\qwindows.dll", "platforms\qwindows.dll") 

includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui"] 
includefiles = [path_platforms] 
excludes = [ 
    '_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 
    'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 
    'Tkconstants', 'Tkinter' 
] 
packages = ["os"] 
path = [] 

# Dependencies are automatically detected, but it might need fine tuning. 
build_exe_options = { 
        "includes":  includes, 
        "include_files": includefiles, 
        "excludes":  excludes, 
        "packages":  packages, 
        "path":   path 
} 

# GUI applications require a different base on Windows (the default is for a 
# console application). 
base = None 
exe = None 
if sys.platform == "win32": 
    exe = Executable(
     script="../Main.py", 
     initScript = None, 
     base="Win32GUI", 
     targetDir = r"dist", 
     targetName="Main.exe", 
     compress = True, 
     copyDependentFiles = True, 
     appendScriptToExe = False, 
     appendScriptToLibrary = False, 
     icon = None 
    ) 

setup( 
     name = "Main", 
     version = "0.1", 
     author = 'me', 
     description = "My GUI application!", 
     options = {"build_exe": build_exe_options}, 
     executables = [exe] 
) 

回答

1

當您在Main.py所在的子文件夾中運行setup.py時,會發生此問題。 我現在將我的setup.py放在與Main.py相同的文件夾中。並將我的.bat文件更改爲python ../setup.py build install

這似乎是cx_Freeze中的一個錯誤,因爲它對於Python 2.7來說工作正常,但不是Python 3.3。

0

你test.py是錯誤的,你不能離開功能空,嘗試

class MyClass(object): 
    def __init__(self): 
     pass 

和setup.py mabye添加 「測試」 到 「包括」

includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui", "Test"] 
+0

我已經試過了。它會導致在Library.zip中創建一個空的Test文件夾。我懷疑正確的結果應該是Test.py文件在Main.zip中以編譯後的pyc結尾。 – Folatt

+1

是否有'Test'文件夾可以找到它而不是你的'Test.py'文件? –

+0

如何將'Test.py'重命名爲'Test1.py' ,然後'includes = [「re」,「sip」,「atexit」,「PyQt5.QtCore」,「PyQt5.QtGui」 ,「Test1」] – Hendry

相關問題