使用 cx_freeze 时如何捆绑其他文件?
我在 Windows 系统上使用 Python 2.6 和 cx_Freeze 4.1.2。我已经创建了 setup.py 来构建我的可执行文件,一切正常。
当 cx_Freeze 运行时,它将所有内容移动到 build
目录。我还想将一些其他文件包含在我的 build
目录中。我该怎么做?这是我的结构:
src\
setup.py
janitor.py
README.txt
CHNAGELOG.txt
helpers\
uncompress\
unRAR.exe
unzip.exe
这是我的片段:
设置
( name='看门人', 版本='1.0', 描述='清洁工', 作者='约翰·多伊', author_email='[电子邮件受保护]', url='http://www.this-page-intentionally-left-blank.org/', 数据文件= [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']), ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']), ('', ['README.txt']) ], 可执行文件= [ 可执行文件\ ( '看门人.py',#initScript ) ] )
我似乎无法让它工作。我需要 MANIFEST.in
文件吗?
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.
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
Here's my snippet:
setup
( name='Janitor', version='1.0', description='Janitor', author='John Doe', author_email='[email protected]', 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 ) ] )
I can't seem to get this to work. Do I need a MANIFEST.in
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
想通了。
注意:
include_files
必须“仅”包含setup.py
脚本的相对路径,否则构建将失败。include_files
可以是字符串列表,即一堆文件及其相对路径或
include_files
可以是一个元组列表,其中元组的前半部分是带有绝对路径的文件名,后半部分是带有绝对路径的目标文件名。(当缺少文档时,请咨询 Kermit the Frog)
Figured it out.
Note:
include_files
must contain "only" relative paths to thesetup.py
script else the build will fail.include_files
can be a list of string i.e a bunch of files with their relative pathsor
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 - wxPyWiki
所有选项的缺少文档位于:cx_Freeze(互联网档案馆)
cx_Freeze
,不过,与Py2Exe
不同,我仍然在单个文件夹中获得包含 11 个文件的构建输出。替代方案: 包装 |老鼠VS。 Python
There's a more complex example at: cx_freeze - wxPyWiki
The lacking documentation of all the options is at: cx_Freeze (Internet Archive)
With
cx_Freeze
, I still get a build output of 11 files in a single folder, though, unlike withPy2Exe
.Alternatives: Packaging | The Mouse Vs. Python
为了找到您的附加文件(
include_files = [->您的附加文件<-]
),您应该在 setup.py 代码中插入以下函数:请参阅 cx-freeze:使用数据文件
In order to find your attached files (
include_files = [-> your attached files <-]
) you should insert the following function in your setup.py code:See cx-freeze: using data files
您还可以创建单独的脚本,在构建后复制文件。我用它在 Windows 上重建应用程序(您应该安装“GNU utility for win32”以使“cp”工作)。
构建.bat:
Also you can create separate script that will copy files after the build. It's what I use to rebuild the app on windows (you should have "GNU utilities for win32" installed to make "cp" works).
build.bat: