0

I have a project setup like this (tell me if it's wrong):

 project/
     module_1/
         __init__.py
         foo.py
     module_2/
         __init__.py
         bar.py

In foo.py:

from module_2 import bar

I get:

ImportError: No module named module_2

However, if I change my project setup to this:

 project/
     module_1/
         __init__.py
         foo.py
         module_2/
             __init__.py
             bar.py

it works. How do I fix this?

Thanks

Walrus the Cat
  • 2,314
  • 5
  • 35
  • 64

1 Answers1

0

Try a relative import:

from ..module_2 import bar

Then you refer to it as just bar: bar.method().

EDIT: add a __main__.py to project and run it from one level up, with

python -m project
matiasg
  • 1,927
  • 2
  • 24
  • 37