Python 3.x cxFreeze如何包含内部项目模块?

Python 3.x cxFreeze如何包含内部项目模块?,python-3.x,cx-freeze,Python 3.x,Cx Freeze,更新: 我怀疑这是cxFreeze中的一个错误,因为我理解这应该是错误的 自动走 结束更新 更新: 我错过了cxFreeze给出的一个错误: Missing modules: ? Test.MyClass imported from main__main__ 结束更新 与sys或PyQt不同,我不确定项目中的模块的正确术语是什么,所以我将使用内部项目模块 下面有一些示例代码,其中我收到错误“ImportError:无法导入名称MyClass”。我想知道如何让cxFreeze编译“Test.py

更新:

我怀疑这是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]
)

您的test.py错误,不能将函数保留为空,请重试

class MyClass(object):
    def __init__(self):
        pass
在setup.py mabye中,将“Test”添加到“includes”中


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


这似乎是cx_Freeze中的一个bug,因为它在Python 2.7中运行良好,但在Python 3.3中运行不好。

我已经尝试过了。它将生成Library.zip中的空测试文件夹。我怀疑正确的结果应该是Test.py文件在Main.zip中以编译后的pyc结束。它是否可以在某个地方找到
Test
文件夹,而不是您的
Test.py
文件?将
Test.py
重命名为类似
Test1.py
,然后
包含=[“re”,“sip”,“atexit”、“PyQt5.QtCore”、“PyQt5.QtGui”、“Test1”]
includes = ["re","sip","atexit","PyQt5.QtCore","PyQt5.QtGui", "Test"]