ModuleNotFoundError&模块导入Python 3.6上的ImportError

时间:2018-04-30 12:41:10

标签: python python-3.x python-module

我已经仔细研究过并发现了许多问题并提出了许多答案,但似乎没有什么能够达到标准。

我在一个名为test的文件夹下设置了两个文件config.pytest.py

config包含代码:

class Config:
    def __init__(self, name):
        self.name = name

虽然测试有:

try:
    # Trying to find module in the parent package
    from . import config
    print(config.debug)
    del config
except ImportError:
    print('Relative import failed')

try:
    # Trying to find module on sys.path
    import config
    print(config.debug)
except ModuleNotFoundError:
    print('Absolute import failed')

根据此stack答案的答案供应商,这已经汇总了。

不幸的是,当我尝试直接调用它时from config import Config我得到ModuleNotFoundError

我真的迷失在这一点上,无法弄清楚从哪里开始。

使用Python 3.6,atom.io作为我的IDE。

0 个答案:

没有答案
相关问题