cx_freeze: How do I add package files into library.zip?

断了今生、忘了曾经 提交于 2019-11-30 12:47:57

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

Then, into setup.py file:

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

Hope that helps

I've solved this problem in Python 3.4 in the following way

import pytz
setup(
    ...
    options = {'build_exe':
        {'include_files': (pytz.__path__[0],), ...},
    }, 
)

Then pytz is included unzipped with all its time zones

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!