0

更新:

我怀疑这是 cxFreeze 中的一个错误,因为我知道这应该自动进行。

结束更新

更新:

我错过了 cxFreeze 给出的错误:

Missing modules:
? Test.MyClass imported from main__main__

结束更新

我不确定与 sys 或 PyQt 不同,项目中的模块的正确术语是什么,所以我将使用内部项目模块。

我在下面有一些示例代码,我收到错误“ImportError:无法导入名称 MyClass”。我很想知道如何让 cxFreeze 编译那个“Test.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_())

测试.py

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

__init.py__

'''empty'''

安装程序.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]
)
4

2 回答 2

1

当您setup.py在 where 所在的子文件夹中运行时,会发生此问题Main.py。我现在把我的放在setup.py同一个文件夹中Main.py。并将我的.bat文件更改为python ../setup.py build install.

这似乎是 cx_Freeze 中的一个错误,因为它适用于 Python 2.7,但不适用于 Python 3.3。

于 2013-08-10T10:52:30.427 回答
0

你的 test.py 错了,你不能把函数留空,试试

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

并在 setup.py mabye 中将“Test”添加到“includes”中

includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui", "Test"]
于 2013-07-10T19:07:44.837 回答