比如说test|--a.py|--b.py`--__init__.pya.pyfromtest.bimportcprint(c)b.pyc="test"运行a.pypython3a.py出错Traceback(mostrecentcalllast):File"a.py",line1,infromtest.bimportcImportError:Nomodulenamed'test.b'我是看官方文档的:https://docspy3zh.readthedocs.org/en/latest/tutorial/modules.html#tut-packages为什么test没有被当成一个包呢?脚本所在的文件夹应该在搜索路径里面的呀。虽然直接import也行,但是用包组织似乎更推荐?如果说因为是包内平级的模块不行,但是文档里面说可以用语句来导入的:https://docspy3zh.readthedocs.org/en/latest/tutorial/modules.html#id18然而将a.py改成:from.importbprint(b.c)依然报错。Traceback(mostrecentcalllast):File"a.py",line1,infrom.importbSystemError:Parentmodule''notloaded,cannotperformrelativeimport将a.py改写成importsysprint(sys.path)输出:['/home/tioover/.proj/test','/usr/lib/python3.3/site-packages/Pectin-0.9-py3.3.egg','/usr/lib/python33.zip','/usr/lib/python3.3','/usr/lib/python3.3/plat-linux','/usr/lib/python3.3/lib-dynload','/usr/lib/python3.3/site-packages','/usr/lib/python3.3/site-packages/setuptools-0.6c11.egg-info']
千万里不及你
哆啦的时光机
相关分类