setuptools troubles -- excluding packages, including data files

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.

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']

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 *