import error in python even after having init file

2019-09-10 17:31发布

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?

1条回答
再贱就再见
2楼-- · 2019-09-10 18:09

Try this:

import sys
sys.path.append('/home/ching')
from maindir import constants
查看更多
登录 后发表回答