Cx_Freeze-自动包含模块 [英] Cx_Freeze - Include Modules automatically

查看:110
本文介绍了Cx_Freeze-自动包含模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该在下面的代码中包括我在.py中使用过的模块,例如 os 模块还是自动完成?关于排除,我使用了<$ c我的.py文件中的$ c> pyqt4 是否有必要在此 setup.py 文件中添加其名称?

  import sys 
来自cx_Freeze导入设置,可执行文件

#自动检测到依赖项,但可能需要进行微调。
build_exe_options = { packages:[ os], excludes:[ tkinter]}

#GUI应用程序在Windows上需要不同的基础(默认为
#控制台应用程序)。
base =无
如果sys.platform == win32:
base = Win32GUI

setup(name = my-app,
版本= 0.9.0,
说明=版权2013​​,
选项= { build_exe:build_exe_options},
可执行文件= [Executable( my_module.py, base = base)])


解决方案

如评论所述,依赖项会自动检测到,但是有时您需要手动对其进行微调。 os和tkinter仅作为示例,您的项目中可能不需要它们。通常,可以检测到您导入导入的任何内容,但是如果以其他方式加载插件库,则找不到它们,因此需要指定它们。 / p>

尝试将其冻结,并查看是否由于缺少任何内容而失败,然后返回并将其添加到 packages 中。


should I include modules that I have used in my .py like os module in code below or its done automatically?and what about exclude?I have used pyqt4 in my .py is it necessary to add its name in this setup.py file?

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "my-app",
        version = "0.9.0",
        description = "Copyright 2013",
        options = {"build_exe": build_exe_options},
        executables = [Executable("my_module.py", base=base)])

解决方案

As the comment says, dependencies are automatically detected, but you sometimes need to fine tune them manually. os and tkinter are just there as examples, you probably don't need them for your project. Generally, anything you've imported can be detected, but if you load plugin libraries some other way, it won't find them, so you need to specify them.

Try freezing it, and see if it fails because anything is missing, then go back and add that to packages.

这篇关于Cx_Freeze-自动包含模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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