首页 > 解决方案 > Python ModuleNotFoundError:没有名为“的模块”''

问题描述

我想从 subdir 导入一个文件,我收到这样的错误:

ModuleNotFoundError:没有名为“特殊”的模块

│   
├── constants.py
├── crawler.py
├── case.py ===================>>>> I working on this file
├── special
    ├── __init__.py
    └── wantToImport.py =================>>>I want to import this file

我的case.py是这样的:

from special.wantToImport import ImportClass

我的 wantToImport.py 文件是这样的:

class ImportClass:

    def mydefination(self):
        #Some codes here
 

我想在我的 case.py 文件上使用 mydefinitioon 函数但我无法导入此文件。为什么我收到此错误?我该如何解决这个问题?

标签: pythonpython-3.x

解决方案


你应该告诉 Python 你的模块路径在当前目录中(使用 a .):

from .special.wantToImport import ImportClass

推荐阅读