使用cx_freeze时如何捆绑其他文件? [英] How can I bundle other files when using cx_freeze?

查看:63
本文介绍了使用cx_freeze时如何捆绑其他文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows系统上使用Python 2.6和cx_Freeze 4.1.2。我已经创建了setup.py来生成我的可执行文件,并且一切正常。

I'm using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I've created the setup.py to build my executable and everything works fine.

cx_Freeze运行时,它将所有内容移至 build 目录。我想在 build 目录中包含其他文件。我怎样才能做到这一点?这是我的结构:

When cx_Freeze runs, it moves everything to the build directory. I have some other files that I would like included in my build directory. How can I do this? Here's my structure:

src\
    setup.py
    janitor.py
    README.txt
    CHNAGELOG.txt
    helpers\
        uncompress\
            unRAR.exe
            unzip.exe

这是我的摘录:


设置

setup

( name='Janitor',
  version='1.0',
  description='Janitor',
  author='John Doe',
  author_email='john.doe@gmail.com',
  url='http://www.this-page-intentionally-left-blank.org/',
  data_files = 
      [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']),
        ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']),
        ('', ['README.txt'])
      ],
  executables =
      [
      Executable\
          (
          'janitor.py', #initScript
          )
      ]
)


我似乎无法让它工作。我是否需要 MANIFEST.in 文件?

I can't seem to get this to work. Do I need a MANIFEST.in file?

推荐答案

from cx_Freeze import setup,Executable

includefiles = ['README.txt', 'CHANGELOG.txt', 'helpers\uncompress\unRAR.exe', , 'helpers\uncompress\unzip.exe']
includes = []
excludes = ['Tkinter']
packages = ['do','khh']

setup(
    name = 'myapp',
    version = '0.1',
    description = 'A general enhancement utility',
    author = 'lenin',
    author_email = 'le...@null.com',
    options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [Executable('janitor.py')]
)

注意:


  • include_files 必须包含 setup.py 脚本的仅相对路径,否则构建将失败。

  • include_files 可以是列表f字符串,即带有相对路径的一堆文件


  • include_files 可以是元组列表其中元组的前半部分是具有绝对路径的文件名,后半部分是具有绝对路径的目标文件名。

  • include_files must contain "only" relative paths to the setup.py script else the build will fail.
  • include_files can be a list of string i.e a bunch of files with their relative paths
    or
  • include_files can be a list of tuples in which the first half of the tuple is the file name with the absolute path and the second half is the destination filename with the absolute path.

(如果缺少文档,请咨询青蛙青蛙专家)

(When the lack of the documentation arises, consult Kermit the Frog)

这篇关于使用cx_freeze时如何捆绑其他文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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