7

I created and published a Python package, but I just can't get it to include a text file.

Here is the repository: https://github.com/void4/gimpscm

The file I need to include is procdump.txt, located in the gimpscm-directory.

So the layout is like this:

setup.py
setup.cfg
MANIFEST.in
gimpscm/
       /__index__.py
       /procdump.txt
       /(other .py files)

I tried:

  • including a package_data directive in setup.py
  • various MANIFEST.in directives

The current setup.py includes:

  package_data = {"gimpscm": ["gimpscm/procdump.txt"]},
  include_package_data=True,

And MANIFEST.in contains:

recursive-include gimpscm *.txt

The txt file is included like the .py files in the gimpscm subdirectory of the zip in the dist directory. But when I pip install gimpscm, the file simply isn't installed.

I publish the package this way:

python setup.py sdist
twine upload dist/*

On the pypi website, the uploaded package DOES include the txt file, it just isn't included on the pip install.

This process so far has been extremely frustrating, and Stackoverflow and other sites do not give a clear answer. I've tried both the MANIFEST.in and setup.py directive approaches, in every combination. It still doesn't work. The Python docs are also too convoluted and unclear for me.

2080
  • 1,223
  • 1
  • 14
  • 37
  • Add it under `package_data` – vin Jun 20 '19 at 14:44
  • Possible duplicate of https://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py – vin Jun 20 '19 at 14:45
  • Possible duplicate of [Including non-Python files with setup.py](https://stackoverflow.com/questions/1612733/including-non-python-files-with-setup-py) – vin Jun 20 '19 at 14:46
  • @vin I did, see the edited question – 2080 Jun 20 '19 at 14:47
  • @vin I tried both approaches, in every combination, it still doesn't work. I've checked all related stackoverflow questions. – 2080 Jun 20 '19 at 14:48
  • Does simply using `include_package_data=True` work ? PS: this usually works for me – vin Jun 20 '19 at 14:49
  • @vin I have. Or do you mean just this statement, and omitting package_data? – 2080 Jun 20 '19 at 14:51
  • yes omit package data and just use the `include_package_data` option – vin Jun 20 '19 at 14:56
  • Also try`from setuptools import setup, find_packages` instead of `from distutils.core import setup` – vin Jun 20 '19 at 14:58

3 Answers3

9

The solution is a combination of @m.rp and @vin's answers:

Instead of from distutils.core import setup use

from setuptools import setup

include the following argument to the setup() call

include_package_data=True,

and ONLY use the MANIFEST.in to include files, where the directory is specified relative from the location where the MANIFEST.in file is.

recursive-include gimpscm *.txt

What a massive PITA this was. Thank you for your answers!

2080
  • 1,223
  • 1
  • 14
  • 37
4

include_package_data is part of the setuptools distro and not distutils Try something like follows

  from setuptools import setup, find_packages

  setup(name="",
        version="0.1.0",
        packages=find_packages(),
        include_package_data=True,
        setup_requires=["pytest-runner"],
        tests_require=["pytest",
                       "mock"],
        test_suite="pytest",
        install_requires=[],
        entry_points={"console_scripts": []})
vin
  • 960
  • 2
  • 14
  • 28
3

You are using both MANIFEST.in and package_data, many sources discourage this use, since you give two sources of truth that can easily be inconsistent with each other.

Use just MANIFEST.in and include_package_data = True

Additional Sources: https://blog.ionelmc.ro/presentations/packaging/#slide:15

m.rp
  • 718
  • 8
  • 22
  • 1
    This does not work for me, see https://pypi.org/project/gimpscm/1.1/ The .txt is still included in the uploaded package, but does not appear in the pip installed package. – 2080 Jun 20 '19 at 15:05