使用__main__.py分发可执行zip文件,如何访问额外的数据? [英] Distributing an executable zip file with __main__.py, how to access extra data?

查看:104
本文介绍了使用__main__.py分发可执行zip文件,如何访问额外的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小程序,我想使用以下配方分发它:

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

  1. 其中包含__main__.py的单个目录
  2. 压缩此目录并在其上添加一个Shebang #!/usr/bin/env python
  3. 使其可执行
  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

问题在于,在此软件包中,我还有其他文件(我使用pygtk工具箱,并且需要图像和ui xml文件).当我尝试访问这些文件时,我看到资源不可用的错误(我试图打开的路径类似于file.zip/gui/gui.ui).

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?

推荐答案

我自己弄清楚,使用pkgutil.get_data来访问包中的数据就足够了.

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

这篇关于使用__main__.py分发可执行zip文件,如何访问额外的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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