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?

3
  • i think bar is a folder not python file(.py) Commented Apr 6, 2017 at 11:31
  • That's right. Why does this impair the installation though? Commented Apr 6, 2017 at 11:33
  • 1
    try this link for init.py stackoverflow.com/questions/1944569/… Commented Apr 6, 2017 at 11:37

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

find_packages() installs the subdirectory, but the import still fails.
Same here, the subdirectories are installed, but cannot import. Found an answer to this at some point?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.