2

Here is my code directory structure:

/root
-/proj1
--/module1.py
--/__init__.py
--/sub_proj1
---/module2.py
---/__init__.py
-/proj2
--/module3.py

If I want to import code from module2.py into module3.py I tried the following import statement:

from .proj1.sub_proj1 import *

but I am getting import error. Is thee anything I need to fix? I am not sure what I am doing wrong with relative imports.

ozn
  • 1,990
  • 3
  • 26
  • 37

1 Answers1

2

Similar to this question:

Python import module from sibling folder

You need an __init__.py in your root and both project folders

Also this should be your import statement:

from ..proj1.sub_proj1 import *
Community
  • 1
  • 1
kujosHeist
  • 810
  • 1
  • 11
  • 25
  • 1
    Thanks for your response. If I were to add the __init__.py and have another folder in root as "proj3" and don't want anything in there imported, do I do just make sure that there is no __init__.py inside "proj3"? – ozn Apr 24 '17 at 07:35