Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

pytz

cx-freeze

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

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

like image 438
mlt Avatar asked May 15 '12 18:05

mlt


2 Answers

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

like image 31
Winand Avatar answered Nov 05 '22 06:11

Winand


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

like image 133
matuuar Avatar answered Nov 05 '22 06:11

matuuar