开发者

py2exe access 'other_resources'

开发者 https://www.devze.com 2023-01-10 14:07 出处:网络
So with py2exe you can add additional data inside the library zip file, now I was wondering, how do you access this dat开发者_如何学运维a, do you need to read it out from the zipfile or can you just a

So with py2exe you can add additional data inside the library zip file, now I was wondering, how do you access this dat开发者_如何学运维a, do you need to read it out from the zipfile or can you just access it like any other file ? or perhaps there's another way to access it.


I personally never used the zipfile. Instead, I pass the data files my program used in the setup method and use the bundle_files option (as described at the bottom of this page). For instance, the program I create using this call

setup(name = "Urban Planning",
      windows = [{'script': "main.py", "dest_base": "Urban_Planning"}],
      options = opts, # Dictionary of options
      zipfile = None, # Don't create zip file
      data_files = Mydata_files) # Add list of data files to folder

also has a piece before it where a config file and some images for the user interface are added like this

Mydata_files = [] # List of data files to include
# Get the images from the [script root]/ui/images/ folder
for files in os.listdir(sys.path[0] + '/ui/images/'):
    f1 = sys.path[0] + '/ui/images/' + files
    if os.path.isfile(f1): # This will skip directories
        f2 = 'ui/images', [f1]
        Mydata_files.append(f2)

# Get the config file from the [script root]/Configs folder
Mydata_files.append(('Configs', [sys.path[0] + '/Configs/defaults.cfg']))

This way I can call my config file just like I would while running the script using idle or command prompt and my UI images display correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消