cx_Freeze不包括子目录中的.py文件 [英] cx_Freeze does not include .py files from subdirectories

查看:63
本文介绍了cx_Freeze不包括子目录中的.py文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python 3.3,Pyside和lxml等构建程序.cx_Freeze就像一种魅力一样工作,直到我开始将模块排序到子目录中以保持整洁.cx_Freeze可以工作,但是报告缺少模块,并且输出的.exe文件无法加载,但是使用.py文件打开程序没有问题.

I'm building a program with Python 3.3, Pyside and lxml amongst others. cx_Freeze was working like a charm until I starting sorting my modules into subdirectories for neatness. 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.

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

My folder structure is simple and only has 2 sub-folders called parsers and constants.

cx_Freeze文档允许添加路径变量,但是不会搜索模块.感谢所有帮助.

The cx_Freeze documentation allows for adding a path variable, but this doesn't search for the modules. 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)]
)

结果导致一个无法运行的exe.

Results in and an exe that can't run.

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

当然,目录必须包含 __ init __.py 才能被视为软件包.

Of course the directories must contain __init__.py in order to be considered packages.

如果这没有达到预期的效果,那么查看 main.py 中使用的导入机制来拉入这些文件将很有用.> import (或从x import 导入),这可能会给cx_Freeze查找问题带来麻烦.

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.

这篇关于cx_Freeze不包括子目录中的.py文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆