Pythonic Guy 21421
Pythonic Guy 21421

Reputation: 401

Python is not recognising a submodule even with __init__,py

I made a project that is a collection of code and seperated them to make it easy to publish to PyPi. I have this directory here:

foo
|   __init__.py
|
\---coordinates
    |   __init__.py
    |
    \---coordinates
            coordinates.py
            __init__.py

However, when i import foo, it does not recognise the coordinates submodule.

>>>import foo
>>>dir(foo)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>>foo.coordinates
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'foo' has no attribute 'coordinates'

What am I doing wrong?

Upvotes: 0

Views: 63

Answers (1)

Saurav Shanu
Saurav Shanu

Reputation: 171

There isn't any point in doing what you are doing. Try doing from foo.coordinates.coordinates import coordinates.

If you still want to do foo.coordinates you must add import [submodule_name] like import coordinates in your __init__.py.

Upvotes: 1

Related Questions