0

I have a PyQt application which needs to show some images. I saw in:

How can I include package_data without a MANIFEST.in file?

A way to include the image files in the package installation.

It works fine in the aspect that /usr/local/lib/python2.7/dist-packages/mypacakge/images/ now contains all the files. Unfortunately images are still not being shown by the app.

My current code addresses the images files as relative paths (i.e: images/foo.jpeg) which I guess is wrong. But I have no idea what is the right way to address them (unless I want to use the absolute /usr/local/lib/python2.7/dist-packages/mypacakge/images/foo.jpeg which I believe I don't). This seems like a common enough issue, yet I can't find any resources/answers on how to do that.

Elad Weiss
  • 3,662
  • 3
  • 22
  • 50

1 Answers1

2

Module pkg_resources has support to locate a file contained in a package:

import pkg_resources

path = pkg_resources.resource_filename('<package name>', 'images/foo.jpeg')
Guybrush
  • 2,680
  • 1
  • 10
  • 17