Including Package Data with setuptools/distutils
Problem:
Despite following the recommended steps to include package data using setuptools, the installer fails to pull in the relevant files. The following setup code should enable this functionality:
<code class="python">setup( name='myapp', packages=find_packages(), package_data={ 'myapp': ['data/*.txt'], }, include_package_data=True, zip_safe=False, install_requires=['distribute'], )</code>
Explanation:
The issue arises due to a subtle difference between package_data and the more reliable MANIFEST.in. package_data is primarily used when building binary packages (e.g., python setup.py bdist ...), but it does not work for creating source packages (e.g., python setup.py sdist ...).
Solution:
To include package data effectively for both binary and source distributions, it is recommended to use MANIFEST.in. Here's an example:
include appname/data/*.txt
Place this file at the root of your project. It will instruct both bdist and sdist commands to include the specified data files. This method ensures that regardless of the distribution type being built, the required data is properly packaged.
The above is the detailed content of Why Does My `setup.py` Fail to Include Package Data?. For more information, please follow other related articles on the PHP Chinese website!