如何在cx_freeze中包含一个文件夹?

Cas*_*ash 18 python cx-freeze

我正在使用cx_freeze来部署我的应用程序.我想包含一个完整的目录,因为包含单个文件不会将它们放在一个文件夹中.我如何包含文件夹?

Ecn*_*o92 25

您必须为构建选项设置包含文件参数.您可以通过不同的方式执行此操作,但我将显示我的配置的一部分.我在这里描述的是针对一个特定文件和一个特定目标.我想你也可以设置这样的路径,但我还没有测试过.

编辑:测试过,请为您的项目选择正确的方法.

buildOptions = dict(include_files = [(absolute_path_to_your_file,'final_filename')]) #single file, absolute path.

buildOptions = dict(include_files = ['your_folder/']) #folder,relative path. Use tuple like in the single file to set a absolute path.

setup(
         name = "appname",
         version = "1.0",
         description = "description",
         author = "your name",
         options = dict(build_exe = buildOptions),
         executables = executables)
Run Code Online (Sandbox Code Playgroud)

另请参阅此主题.它可以解决相同的问题:在使用cx_freeze时如何捆绑其他文件?

  • 我刚刚为你测试了它,它真的很容易.我将用相对路径证明这一点.所以我的文件夹"testfolder"在项目文件夹中.使用 - > include_files = ['testfolder /'], - 它会起作用.现在我的testfolder包含其中的所有文件都包含在构建中.您也可以在绝对路径中执行此操作,但提醒您需要使用元组而不是指定相对路径.正如您所看到的,这是原始答案的有效解决方案. (4认同)
  • 您必须将absolute_path_to_your_file替换为要包含的源文件的目标.绝对路径大多是这样的:基于Windows的系统上的"C:// your_folder/a_subfolder". (2认同)