簡體   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





日志解析器內部是這個導入

from ingestor import Ingestor

但是每當攝取器文件到達這里

from scripts import create_app, db它失敗並顯示錯誤消息

ModuleNotFoundError:沒有名為“腳本”的模塊(venv)

我嘗試更改init .py 文件所在的目錄,但沒有成功。 我也嘗試過導入目錄中的所有內容,但也失敗了。 所以我沒有想法?

如果使用“/”,則表示__init__.py和 ingestor 位於同一文件夾中。 確保在這個(攝取文件夾)中有外部__init__.py文件,然后重試。

如果是,但總是面臨同樣的問題,請嘗試這樣的相對導入: from.ingestor import Ingestor 不要錯過“攝取”之前的“點”

如果它不起作用,請嘗試最后一個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM