Search code examples
pythonsetuptoolssetup.py

How do tell setuptools to get my package from src/mypackage


I have a package directory setup like this

package_dir
|-src
| |-mypackage
|   |-__init__.py
|
|-setup.py

How do I set up setup.py to enable me to import mypackage

I've tried: I run python setup.py bdist_wheel where setup.py has options...

packages=find_packages(include=["src"]),
package_dir={"": "src"},

When I run pip install path/to/mypackage.whl it installs fine But when I do python -c "import mypackage" it fails with ModuleNotFoundError while python -c "import src.mypackage" is fine


Solution

  • find_packages(where='src')
    

    Use where, not include. exclude/include are for further filtering found packages. See:

    $ python
    Python 2.7.13 (default, Nov 24 2017, 17:33:09) 
    [GCC 6.3.0 20170516] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from setuptools import find_packages
    >>> find_packages()
    []
    >>> find_packages(include=['src'])
    []
    >>> find_packages(where='src')
    ['mypackage']