10

The source for the package is here

I'm installing the package from the index via:

easy_install hackertray
pip install hackertray

easy_install installs images/hacker-tray.png to the following folder:

/usr/local/lib/python2.7/dist-packages/hackertray-1.8-py2.7.egg/images/

While, pip installs it to:

/usr/local/images/

My setup.py is as follows:

from setuptools import setup
setup(name='hackertray',
      version='1.8',
      description='Hacker News app that sits in your System Tray',
      packages=['hackertray'],
      data_files=[('images', ['images/hacker-tray.png'])])

My MANIFEST file is:

include images/hacker-tray.png
Nemo
  • 3,104
  • 2
  • 30
  • 46

1 Answers1

17

Don't use data_files with relative paths. Actually, don't use data_files at all, unless you make sure the target paths are absolute ones properly generated in a cross-platform way insted of hard coded values.

Use package_data instead:

setup(
    # (...)
    package_data={
        "hackertray.data": [
            "hacker-tray.png",
        ],
    },
)

where hackertray.data is a proper python package (i.e. is a directory that contains a file named __init__.py) and hacker-tray.png is right next to __init__.py.

Here's how it should look:

.
|-- hackertray
|   |-- __init__.py
|   `-- data
|       |-- __init__.py
|       `-- hacker-tray.png
`-- setup.py

You can get the full path to the image file using:

from pkg_resources import resource_filename
print os.path.abspath(resource_filename('hackertray.data', 'hacker-tray.png'))

I hope that helps.

PS: Python<2.7 seems to have a bug regarding packaging of the files listed in package_data. Always make sure to have a manifest file if you're using something older than Python 2.7 for packaging. See here for more info: https://groups.google.com/d/msg/python-virtualenv/v5KJ78LP9Mo/OiBqMcYVFYAJ

Burak Arslan
  • 7,671
  • 2
  • 15
  • 24
  • A few clarifications: 1) What do you mean when you say `hackertray.data` is a _proper python package_? Do I need to create another package just for the data, or is it still part of the original package. 2)I did what you said and the resulting distribution still does not put the image file in its proper place. I've uploaded the package [here](http://ge.tt/66oOe871/v/0). – Nemo Dec 04 '13 at 10:50
  • 1
    For your specific case: `cd hackertray-1.9; mkdir hackertray/data; touch hackertray/data/__init__.py; mv hackertray/hacker-tray.png hackertray/data;` and add `hackertray.data` to `packages` list in setup.py – Burak Arslan Dec 04 '13 at 11:29
  • Also, i'd just use `find_packages()` instead of manually writing a package list. `from setuptools import find_packages` and pass `packages=find_packages()` to `setup`. – Burak Arslan Dec 04 '13 at 11:30