【问题标题】:Failed import for Sentry_sdk in Django在 Django 中导入 Sentry_sdk 失败
【发布时间】:2021-08-31 15:59:21
【问题描述】:

我目前正在尝试让 Sentry 与我的 Django 项目一起工作。在 settings.py 文件中初始化 Sentry 时出现此错误:

第 301 行,在模块中 导入 sentry_sdk ModuleNotFoundError:没有名为“sentry_sdk”的模块 无法加载应用程序 0 (mountpoint='')(未找到可调用或导入错误)

我复制了文档,但我想知道为什么会这样。有没有人遇到过这个问题?我的 Django 版本是 2.2.11,我正在运行 python v 3.9.5

如果重要的话,这里是文档的代码(pip install --upgrade sentry-sdk)

import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    integrations=[DjangoIntegration()],

    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for performance monitoring.
    # We recommend adjusting this value in production,
    traces_sample_rate=1.0,

    # If you wish to associate users to errors (assuming you are using
    # django.contrib.auth) you may enable sending PII data.
    send_default_pii=True,

    # By default the SDK will try to use the SENTRY_RELEASE
    # environment variable, or infer a git commit
    # SHA as release, however you may want to set
    # something more human-readable.
    # release="myapp@1.0.0",
)

【问题讨论】:

    标签: python django sentry


    【解决方案1】:

    您确定在您的环境中安装了sentry 吗? 确保您在运行代码的同一环境中运行 pip install sentry-sdk

    【讨论】:

    • 是的,它已安装
    • 您找到答案了吗?我面临同样的问题。
    【解决方案2】:

    我必须在我的需求文件中包含 sentry-sdk==1.1.0 才能让它运行。

    【讨论】:

    • 如果您使用 docker,这可能会起作用,因为 docker 使用需求文件来创建映像。添加后,您可能还需要删除/重建图像。
    猜你喜欢
    • 2012-03-28
    • 2013-02-13
    • 2022-01-02
    • 2018-11-11
    • 2019-09-04
    • 2018-11-17
    • 2020-11-02
    • 2015-02-14
    • 1970-01-01
    相关资源
    最近更新 更多