简体   繁体   English

Python - 没有名为错误的模块。 无论我将 __init__.py 文件放在哪里,摄取器文件似乎都无法访问它

[英]Python- no module named error. wherever i place the __init__.py file the ingestor file just cant seem to get at it


project structure


__init__.py
backend

      __init__.py

      /log_parser.py

      /ingestor

      /data_aggregation

configuration

scripts

    __init__.py(holding create_app and db)

UI

utils

    /__init__.py

    /models





inside of the log parser is this import日志解析器内部是这个导入

from ingestor import Ingestor

however whenever the ingestor file gets to here但是每当摄取器文件到达这里

from scripts import create_app, db it fails with the error message from scripts import create_app, db它失败并显示错误消息

ModuleNotFoundError: No module named 'scripts' (venv) ModuleNotFoundError:没有名为“脚本”的模块(venv)

ive tried changing the directory the init .py file is in with no luck.我尝试更改init .py 文件所在的目录,但没有成功。 I've also tried importing everything within a directory which also failed.我也尝试过导入目录中的所有内容,但也失败了。 so i'm out of ideas?所以我没有想法?

If with "/" you mean that the __init__.py and ingestor ar on the same folder.如果使用“/”,则表示__init__.py和 ingestor 位于同一文件夹中。 Make sure that inside this one (ingestor folder) there is outher __init__.py file and try again.确保在这个(摄取文件夹)中有外部__init__.py文件,然后重试。

If yes but always facing the same problem, try with a relative import like this: from.ingestor import Ingestor .如果是,但总是面临同样的问题,请尝试这样的相对导入: from.ingestor import Ingestor Don't miss the "dot" before "ingestor"不要错过“摄取”之前的“点”

If it doesn't work try this last one:如果它不起作用,请尝试最后一个:

import sys
sys.path.append(".")
from ingestor import Ingestor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM