python - 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 函数但我无法导入此文件。为什么我收到此错误?我该如何解决这个问题?
解决方案
你应该告诉 Python 你的模块路径在当前目录中(使用 a .
):
from .special.wantToImport import ImportClass
推荐阅读
- c# - 将元素添加到xml文件中特定位置的多个父节点
- git - 从分支到 TFS 中的关联工作项
- python - for 句中的单矩阵减法
- android - 奥利奥中的 FileUriExposedException
- javascript - html 选项是否支持鼠标悬停事件?
- azure - 如何将 Azure WebJob 配置为从 git 部署的 exe 运行,而不是从上传运行?
- java - Mockito 显示错误的 UnnecessaryStubbingException
- git - 将 git 文件从 jenkins 部署到 ubuntu 服务器
- wcf - 如何使用新字段(Dynamics AX 2012)扩展我的 WCF 服务?
- sql - presto - 获取天数间隔(不是日期)