0

i'm having troubles with python importing. Here is my structure.

 fitness/
    __init__.py
    authentication/ 
       __init__.py
       views.py
       urls.py 
    views.py 
    urls.py 

from authentication.views i'm trying to import the fitness.views

I've been trying to use

from fitness import views 

which eclipse reads fine, but when i run it it says

No module named fitness
Tadeck
  • 132,510
  • 28
  • 152
  • 198
Lilluda 5
  • 1,111
  • 3
  • 18
  • 38

1 Answers1

0

You need to add the directory containing the module you're trying to import (fitness.views) to the PYTHONPATH. Put this at the beginning of your module. It adds '../../' to the PYTHONPATH. That is the directory containing the fitness folder, so you can import the module without any problem.

import sys, os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from fitness import views
pycoder112358
  • 875
  • 5
  • 10