0

I have a python project looks like this:

src
 |
 +---- __init__.py
 |
 +---- branch2
         |
         +----__init__.py
         +----xx.py
 |
 +---- branch3
         |
         +---- __init__.py
         +---- yy.py

I want to import a python file in yy.py from a sibling package:

from branch2 import xx

but I got error:

ImportError: No module named xx

I'm sure that every package has a init.py file ,and my python version is 2.7.10

2 Answers2

0

Have you ensured that your PYTHONPATH is pointed at the scr directory? Not doing so will generate this error.

Usherwood
  • 359
  • 3
  • 11
0

Whenever python interpreter encounters an import statement it looks into PYTHONPATH for that module.In your case interpreter is not able to find module in PYTHONPATH. add the below line of code in the beginning of your python file.

import sys;
sys.path.insert('../')
Eric Aya
  • 69,473
  • 35
  • 181
  • 253