Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including non-python files in a python package

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.

like image 817
2080 Avatar asked Dec 17 '22 16:12

2080


1 Answers

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!

like image 99
2080 Avatar answered Dec 30 '22 12:12

2080