setuptools troubles — excluding packages, including data files

Each Answer to this Q is separated by one/two green lines.

I’m fairly new to setuptools. I’ve seen a few similar questions and it drives a little bit insane that I’ve seemed to follow advice I saw but setuptools still does something different than what I want.

Here is the structure of my project:


And here is the contents of my

#!/usr/bin/env python
import os
#from distutils.core import setup
from setuptools import setup, find_packages

    package_data = {
        '': ['LICENSE', 'README.md5', 'RELEASE']

Also, in my manifest file I have:

include LICENSE
include RELEASE

I build the tar with:

python sdist

I want to:

  1. Exclude tests directory from the source distribution;
  2. Have LICENSE,, RELEASE files in the site-packages directory, either at the top level, or inside the package1 directory (at this point I will agree to either).

Instead, here’s what happens:

  1. tests directory remains to be in the created tar archive and gets installed to the site-packages;
  2. Files are copied to the archive, but do not get installed to the site-packaged directory of the package.

I am out of ideas, can someone explain to me what I am doing wrong and how to fix it?

find_packages uses fnmatchcase for its exclude filtering. You can test if your exclusion pattern matches a package name as follows:

>>> from fnmatch import fnmatchcase
>>> fnmatchcase('', 'tests')

Assuming all the tests in your project live in package names ending in tests or subpackages of those packages, the following should suffice to exclude all the test code:

    packages=find_packages(exclude=['tests', '*.tests', '*.tests.*']),    

To also exclude the tests folder from source distributions, add the following to

recursive-exclude tests *

You should create a new file called in the root level of your package, then follow these instructions:

  1. To control which files end up in your tar file, create a new file called in the root level of your package. For example, you can exclude whole directories from your distribution, using recursive-exclude in the file. In your case, you need your file to contain:

    recursive-exclude tests *
  2. It’s not common to include README and other files in the site-packages directory, but if you really want to, then go inside package1 and create symbolic links to the files you want to include:

    cd package1
    ln -s ../LICENSE
    ln -s ../
    ln -s ../RELEASE

    Then change the following line in your

    package_data = {
        '': ['LICENSE', '', 'RELEASE']


    package_data = {
        'package1': ['LICENSE', '', 'RELEASE']

I was trying everything and nothing seemed to work, until I deleted the build directory (after seeing another answer mentioning *.egg-info/ directory) and it finally worked. python clean --all should also do the job.

if your structure is true:

  1. the tests folder is not a package (it doesn’t have the file), so find_package don’t exclude it.
  2. include_package_data=True mean that all versionned files will be included if not explicitly excluded .

so : try an exclude tests/* in your

I Hope it had helped would take care of it.

prune tests/

if you have static files to be added, add them with

recursive-include package1/static *

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .