当前程序目录结构是这样的main.py的代码:#! /usr/bin/env python# encoding:utf-8from A import call_a
def main(): call_a()if __name__ == '__main__':
main()A.py文件的代码:#! /usr/bin/env python# encoding:utf-8from B import call_b
def call_a():
print "call_a"
call_b()B.py文件代码:#! /usr/bin/env python# encoding:utf-8def call_b():
print "Call_b"当我通过bash命令运行脚本:bogon:tests nooper$ python innermodules/main.py
Traceback (most recent call last):
File "innermodules/main.py", line 4, in <module> from A import call_aImportError: No module named Abogon:tests nooper$是不能识别模块的加载路径,但是能通过IDE-pycharm运行。
2 回答

杨__羊羊
TA贡献1943条经验 获得超7个赞
可以直接通过pycharm来修改import的路径,具体pycharm版本不一样,对应按钮位置不一样,因此仅以文字说明。
file->Settings(Ctrl+Shift+s)->Project Setting->Project Interpreter->选择你的python版本->Interpreter Path->添加
你这里的话添加如下目录即可
**\tests
即project的根目录。
如果你在tests下有文件夹test2,其下有文件c.py。要引用c文件的c2
在你的main.py里面加入:
from test2.c import c2
路径是以你添加的路径的相对路径。
添加回答
举报
0/150
提交
取消