4

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?

Flux
  • 9,805
  • 5
  • 46
  • 92
pygabriel
  • 9,840
  • 4
  • 41
  • 54
  • You're adding the shebang onto the zipped directory? I don't think python will run with a binary file (zip). How are you making it executable? – Nick T May 18 '10 at 17:31
  • 1
    I'm following this: http://sayspy.blogspot.com/2010/03/various-ways-of-distributing-python.html in particular: `echo "#\!"$(which python) | cat - oplop.zip > /usr/bin/oplop` – pygabriel May 18 '10 at 17:50
  • Pygabriel, the method of determining the Python path seems wrong. Running `$(which python)` like this is generating the path for Python on *your local system*, where you are building the zip. When you distribute it to others, they may not have Python at the same path. I would recommend `echo "#!/usr/bin/env python` -- this will execute on the machine you are distributing to and determine the correct Python path at the time the zip/script is invoked. – Chris Johnson Mar 28 '14 at 21:18

1 Answers1

8

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

pygabriel
  • 9,840
  • 4
  • 41
  • 54