Home > Article > Backend Development > How to Properly Include Package Data with setuptools/distutils?
Including Package Data with setuptools/distutils
When configuring package installation using setuptools, difficulties may arise in incorporating package_data files. This article addresses the correct approach to do so and provides a solution to common issues.
Incorrect Approach
The incorrect approach involves defining package_data and setting include_package_data to True, as seen in the provided example:
<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>
Correct Approach
The issue with the incorrect approach is that package_data is only utilized when building binary packages (e.g., python setup.py bdist ...) but not when building source packages (e.g., python setup.py sdist ...).
The correct approach involves using MANIFEST.in to specify files included in both binary and source distributions. Here's an example of a MANIFEST.in file:
include *.txt recursive-include myapp/data *
By using MANIFEST.in, you can ensure that all necessary package data is included regardless of the distribution type being built.
The above is the detailed content of How to Properly Include Package Data with setuptools/distutils?. For more information, please follow other related articles on the PHP Chinese website!