即使在拥有init文件和python路径之后,python中也会出现导入错误
我正在尝试用python导入一个文件 我的目录结构是即使在拥有init文件和python路径之后,python中也会出现导入错误,python,import,package,python-import,Python,Import,Package,Python Import,我正在尝试用python导入一个文件 我的目录结构是 maindir __init__.py constants.py subdirectory __init__.py code.py 我正在尝试在代码文件中导入常量 import sys sys.path.append('/home/ching/maindir') from maindir import constants 即使在那之后,我也会犯这个错误 ImportErro
maindir
__init__.py
constants.py
subdirectory
__init__.py
code.py
我正在尝试在代码文件中导入常量
import sys
sys.path.append('/home/ching/maindir')
from maindir import constants
即使在那之后,我也会犯这个错误
ImportError: No module named maindir
有人知道怎么了吗?试试这个:
import sys
sys.path.append('/home/ching')
from maindir import constants
试试这个:
import sys
sys.path.append('/home/ching')
from maindir import constants
如果解决了你的问题,别忘了接受答案。如果解决了你的问题,别忘了接受答案。