cx\u Freeze不包括子目录中的.py文件

2024-05-15 03:54:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python3.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。在

^{pr2}$

Tags: 模块文件pyimportbuild程序文件夹base
2条回答

您应该能够非常简单地包括您的软件包:

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

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

如果这没有达到预期的效果,那么可以查看main.py中使用的导入机制来拉入这些文件。如果它执行的不是直接的import(或from x import),则可能会导致cx在查找它时出现冻结问题。在

您应该在setup.py脚本中包含.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}

...

希望这有帮助。在

相关问题 更多 >

    热门问题