cx_Freeze不包含子目录中的.py文件

时间:2014-03-22 14:52:13

标签: python cx-freeze

我正在使用Python 3.3,Pyside和lxml等构建程序。 cx_Freeze像魅力一样工作,直到我开始将模块分类到子目录中以获得整洁。 cx_Freeze工作但报告模块丢失,输出.exe文件无法加载,但使用.py文件打开程序没有问题。

我的文件夹结构很简单,只有2个子文件夹,分别是解析器和常量。

cx_Freeze文档允许添加路径变量,但这不会搜索模块。所有帮助表示赞赏。

import sys
from cx_Freeze import setup,Executable

includefiles = ['open.png', 'appicon.png']
includes = []
excludes = ['Tkinter']
packages = ['lxml._elementpath','lxml.etree']
build_exe_options = {'excludes':excludes,'packages':packages,'include_files':includefiles}

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

setup(
    name = 'Config-Sheets',
    version = '0.1',
    description = 'Convert system configuration into .XLSX files',
    author = 'ZZZ',
    author_email = 'XXX@YYY.com',
    options = {'build_exe': build_exe_options }, 
    executables = [Executable('main.py', base=base)]
)

结果和无法运行的exe。

Missing modules:
...
? parsers.parsercelerra imported from main__main__
? parsers.parserVPLEX imported from main__main__
? parsers.parserrain imported from main__main__

2 个答案:

答案 0 :(得分:2)

您应该可以非常简单地包含您的包:

packages = ['lxml._elementpath','lxml.etree', 'parsers', 'constants']

当然,目录必须包含__init__.py才能被视为包。

如果这没有达到预期的效果,那么查看main.py中使用的导入机制来提取这些文件会很有用。如果它做了一些非直截了当的事情{ {1}}(或import)这可以让cx_Freeze找到问题。

答案 1 :(得分:-2)

您应该在.py脚本中包含setup.py个文件。如果该文件不是Python本身的一部分,则cx_freeze需要知道您希望包含这些文件。您应该将额外的.py文件及其路径添加到includefiles列表中。例如:

import sys
from cx_Freeze import setup,Executable

includefiles = ['open.png', 'appicon.png', 'parsers\xtra_file1.py','constants\xtra_file2.py']
includes = []
excludes = ['Tkinter']
packages = ['lxml._elementpath','lxml.etree']
build_exe_options = {'excludes':excludes,'packages':packages,'include_files':includefiles}

...

希望这会有所帮助。

相关问题