cx_freeze:如何将软件包文件添加到library.zip? [英] cx_freeze: How do I add package files into library.zip?

查看:120
本文介绍了cx_freeze:如何将软件包文件添加到library.zip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试为Windows滚动zip时,我注意到pytz缺少zoneinfo文件夹。现在我有一个在 python setup.py build 之后使用的解决方法,即

I've noticed that pytz misses zoneinfo folder when I try to roll a zip for Windows. Right now I have a workaround that I use after python setup.py build, namely

7z a -xr!*.py* build\exe.win32-2.7\library.zip C:\Python27\Lib\site-packages\pytz

是否有正确的方法可以从 setup.py 或其他方式实现? / p>

Is there a proper way to achieve that from setup.py or something?

推荐答案

您可以解决此问题,并添加以下方法:

You could fix this, adding the following method:

def include_files():
        path_base = "C:\\Python27\\Lib\\site-packages\\pytz\\zoneinfo\\"
        skip_count = len(path_base) 
        zip_includes = [(path_base, "pytz/zoneinfo/")]
        for root, sub_folders, files in os.walk(path_base):
            for file_in_root in files:
                zip_includes.append(
                        ("{}".format(os.path.join(root, file_in_root)),
                         "{}".format(os.path.join("pytz/zoneinfo", root[skip_count:], file_in_root))
                        ) 
                )      
        return zip_includes

然后进入setup.py文件:

Then, into setup.py file:

build_exe_options = {"packages": ["os"],
                     "excludes": ["tkinter"],
                     "zip_includes": include_files(),
                     ...
                     }

希望有帮助

这篇关于cx_freeze:如何将软件包文件添加到library.zip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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