Home > Backend Development > Python Tutorial > How to Properly Include Package Data with setuptools/distutils?

How to Properly Include Package Data with setuptools/distutils?

Susan Sarandon
Release: 2024-11-03 22:16:03
Original
374 people have browsed it

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>
Copy after login

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 *
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template