简体   繁体   中英

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.

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": []})

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM