Distributing an executable zip file with __main__.py, how to access extra data? [duplicate]

大兔子大兔子 提交于 2019-12-22 07:58:16

问题


I'm doing a little program and I want to distribute it using this recipe:

  1. single directory with __main__.py in it
  2. zip this directory and adding a shebang on it #!/usr/bin/env python
  3. making it executable

The problem is that in this package I have also extra files (I'm using pygtk toolkit and I need images and ui xml files). When I try to access these files I have the error that the resource is unavailable (the path that I'm trying to open is something like file.zip/gui/gui.ui ).

How can I handle this situation?


回答1:


I figured out by myself, It's sufficient to use pkgutil.get_data to access the data inside a package.



来源:https://stackoverflow.com/questions/2859413/distributing-an-executable-zip-file-with-main-py-how-to-access-extra-data

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