简体   繁体   中英

Python setup.py: How to get find_packages() to identify packages in subdirectories

I'm trying to create a setup.py file where find_packages() recursively finds packages. In this example, foo , bar , and baz are all modules that I want to be installed and available on the python path. For example, I want to be able to do import foo, bar, baz . The bar-pack and foo-pack are just regular non-python directories that will contain various support files/dirs (such as tests, READMEs, etc. specific to the respective module).

├── bar-pack
│   └── bar
│       └── __init__.py
├── baz
│   └── __init__.py
├── foo-pack
│   └── foo
│       └── __init__.py
├── setup.py

Then say that setup.py is as follows:

from setuptools import setup, find_packages
setup(
    name="mypackage",
    version="0.1",
    packages=find_packages(),
)

However, when I run python setup.py install or python setup.py sdist , only the baz directory is identified and packaged.

I can simplify it down further, and run the following command, but again, only baz is identified.

python -c "from setuptools import setup, find_packages; print(find_packages())"
['baz']

Do you know how I might extend the search path (or manually hard-code the search path) of the find_packages()?

Any help is appreciated.

Setuptools' find_packages supports a "where" keyword ( docs ), and returns a plain old list. You could use that:

from setuptools import setup, find_packages

setup(
    ...,
    packages=find_packages()
    + find_packages(where="./bar-pack")
    + find_packages(where="./foo-pack"),
)

Or, you can just list them manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM