Home > Article > Backend Development > Why Does `package_data` Fail to Include Data Files in Python Setuptools?
Including Package Data in Setups with Setuptools or Distutils
When working with setuptools, integrating package data into the installation process can encounter hurdles. While documentation suggests using package_data to specify file inclusion, users face issues in implementing this approach.
Consider the following code snippet:
setup( name='myapp', packages=find_packages(), package_data={ 'myapp': ['data/*.txt'], }, include_package_data=True, zip_safe=False, install_requires=['distribute'], )
In this example, the package_data dictionary aims to include all .txt files located in the myapp/data/ directory. Однако, this mechanism is ineffective.
An Alternative Approach: MANIFEST.in
Rather than relying on package_data, utilize the MANIFEST.in file to specify the files to be included. This method works seamlessly for both binary and source distributions.
To create a MANIFEST.in file, add the following lines:
include data/*
In this case, it ensures all files within the data/ directory are included in the installation process.
By adopting the MANIFEST.in approach, you can effectively manage package data inclusion in both binary and source distributions.
The above is the detailed content of Why Does `package_data` Fail to Include Data Files in Python Setuptools?. For more information, please follow other related articles on the PHP Chinese website!