make distutils in Python automatically find packages

user248237 picture user248237 · Oct 19, 2012 · Viewed 23.8k times · Source

When describing a python package in setup.py in distutils in Python, is there a way to make it so automatically get every directory that has a __init__.py in it and include that as a subpackage?

ie if the structure is:

mypackage/__init__.py
mypackage/a/__init__.py
mypackage/b/__init__.py

I want to avoid doing:

packages = ['mypackage', 'mypackage.a', 'mypackage.b']

and instead just do:

packages = ['mypackage']

and have it automatically find things like a and b since they have an init file. thanks.

Answer

dm76 picture dm76 · Jan 17, 2013

I would recommend using the find_packages() function available with setuptools such as:

from setuptools import setup, find_packages

and then do

packages=find_packages()