Search code examples
pythonbuildinstallationsetuptoolsdistutils

How to make setup.py install multiple top-level packages?


I have a python package that I would like to organize like so:

root/
    setup.py
    package1/
        __init__.py
        package2/
            __init__.py
        package3/
            __init__.py

I would like setup.py to install package1, package2, and package3 into the correct site-packages/ directory as top level packages, so that I could execute

import package1
import package2
import package3

without a problem. Perhaps this needs multiple setup.py files?

But most importantly, I'd like to ultimately be able to install all three packages by executing pip install root. How do I do this? Preferably a distutils-only solution, though setuptools is ok as well.


Solution

  • I feel it is cleaner to have your development file/folder structure more closely represent the deployment structure.

    What this means is, I'd place all three packages at the same level instead of nesting them.

    If you subsequently want to be able to import all three via one of them, you can set up a dependency in your single setup.py file.