1

I have been fiddling with the MANIFEST.IN file and setup parameters package_data and data_files (both distutils and setuptools) for hours, and I can't figure out how to include data files when building and installing a python package. I managed to get some results when I run python setup.py sdist, but not with python setup.py install --user and not with pip install . --user.

Let's consider the following simple package structure:

mypackage/
    mymodule/
        __init__.py
        gui.py
    data/
        icons/
            icon1.png
    MANIFEST.in
    setup.py

What should I put in setup.py and MANIFEST.in to have data/icons/icon1.png copied in my build and install directories?

I would prefer an opt-in solution (declare all files that must be included).

EDIT: 

It turns out I can make it work when I use python setup.py install --user, using data_files parameter in setup(). The problem is with pip install . --user, which is the preffered way of installing my software. I find this strange, I always thought pip install was roughly doing the same thing as python setup.py install.

PiRK
  • 893
  • 3
  • 9
  • 24
  • This may be a duplicate of [this question](http://stackoverflow.com/questions/7522250/how-to-include-package-data-with-setuptools-distribute). Basically, MANIFEST.in should be used for building sdists or bdists, and setuptools' `include_package_data` or similar directives only works for bdists. If you're going to distribute as both, you can use both solutions. Note that `data_files` is entirely different and is for distributing data files from the package onto the target system at install time (and requires installing from an sdist, not a wheel). – MPlanchard Mar 31 '16 at 14:21
  • Thanks, but distributing is not the problem. The problem is installing. I found some clues here: https://wiki.python.org/moin/Distutils/Cookbook/InstallDataScattered?action=show&redirect=DistutilsInstallDataScattered A couple of examples: https://github.com/kif/pyFAI/blob/master/setup.py#L312 https://github.com/vasole/pymca/blob/master/setup.py#L544 But I can't believe installing icons is such a complex problem. – PiRK Mar 31 '16 at 14:55
  • Another dirty fix would be to declare my data folders as subpackages and add empty __init__.py in each directory, but that's extremely dirty. – PiRK Mar 31 '16 at 15:01
  • I have never had a problem with the install, as long as everything is included in the sdist. Have you checked the egg info to ensure that all of your files are actually being included? Also, it can be useful to totally wipe out any egg-info and build directories prior to rebuilding. Sometimes their being there can mess up inclusion of new files. – MPlanchard Mar 31 '16 at 16:37
  • It turns out I can make it work when I use ``python setup.py install --user``. The problem is with ``pip install . --user``, which is the preffered way of installing my software. I find this strange, I always thought ``pip install`` was roughly doing the same thing as ``python setup.py install``. – PiRK Apr 08 '16 at 11:23
  • More fun facts: it works with ``pip install`` if I import ``install_data`` from ``distutils.command.install_data`` rather than from ``setuptools.command.install_data`` – PiRK Apr 08 '16 at 13:20

0 Answers0