17

I have a Python project with the layout

setup.py
foobar/
    __init__.py
    foo.py
    bar/
        __init__.py

Where the foobar/__init__.py reads

from . import foo
from . import bar

and setup.py

from setuptools import setup

setup(
    name='foobar',
    version='0.0.1',
    packages=['foobar'],
    )

When doing import foobar from the source directory, it all works as expected. However, when installing the package via pip install ., the subfolder bar/ is not installed, leading to the import error

ImportError: cannot import name bar

Any hints?

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249

1 Answers1

27

Apparently to include subpackages, you need find_packages():

from setuptools import setup, find_packages

setup(
    name='foobar',
    version='0.0.1',
    packages=find_packages()
    )

This is recommended​ in the setuptools docs as well.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249