Ching Chong
Ching Chong

Reputation: 723

import error in python even after having init file and python path

I am trying to import a file in python

my directory structure is

maindir
    __init__.py
    constants.py

    subdirectory
          __init__.py
          code.py

I am trying to import constants in the code file

import sys
sys.path.append('/home/ching/maindir')
from maindir import constants

even after that I am getting this error

ImportError: No module named maindir

Any one got any idea whats wrong?

Upvotes: 0

Views: 5293

Answers (1)

user647772
user647772

Reputation:

Try this:

import sys
sys.path.append('/home/ching')
from maindir import constants

Upvotes: 5

Related Questions