简体   繁体   English

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

[英]cx_Freeze does not include .py files from subdirectories

I'm building a program with Python 3.3, Pyside and lxml amongst others.我正在使用 Python 3.3、Pyside 和 lxml 等构建程序。 cx_Freeze was working like a charm until I starting sorting my modules into subdirectories for neatness. cx_Freeze 一直在工作,直到我开始将我的模块分类到子目录中以保持整洁。 cx_Freeze works but reports the modules as missing and the output .exe file fails to load, but there are no issues opening the program with the .py file. cx_Freeze 工作但报告模块丢失并且输出 .exe 文件无法加载,但使用 .py 文件打开程序没有问题。

My folder structure is simple and only has 2 sub-folders called parsers and constants.我的文件夹结构很简单,只有 2 个子文件夹,称为解析器和常量。

The cx_Freeze documentation allows for adding a path variable, but this doesn't search for the modules. cx_Freeze 文档允许添加路径变量,但这不会搜索模块。 All help appreciated.所有帮助表示赞赏。

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)]
)

Results in and an exe that can't run.结果和一个无法运行的exe。

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

You should be able to include your packages very simply:您应该能够非常简单地包含您的包:

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

Of course the directories must contain __init__.py in order to be considered packages.当然,目录必须包含__init__.py才能被视为包。

If this doesn't achieve the desired effect then it would be useful to see the import mechanism used in main.py to pull these files in. If it's doing anything other than a straightforward import (or from x import ) this can give cx_Freeze problems finding it.如果这没有达到预期的效果那么就可以看到所使用的进口机制的有益main.py拉在这些文件中,如果它做的不是一个简单的任何其他import (或from x import )这可以给cx_Freeze问题找到它。

You should include your .py files in the setup.py script.您应该在setup.py脚本中包含您的.py文件。 If the file is not a part of Python itself, cx_freeze needs to know that you want those files included.如果该文件不是 Python 本身的一部分,则 cx_freeze 需要知道您希望包含这些文件。 You should add your extra .py files with their paths to the includefiles list.您应该将额外的.py文件及其路径添加到包含includefiles列表中。 For instance:例如:

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}

...

Hope this helped.希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM