在 Django 中导入 Sentry_sdk 失败

7 python django sentry

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

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

我复制了文档,我想知道为什么会发生这种情况。以前有人遇到过这个问题吗?我的 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",
)
Run Code Online (Sandbox Code Playgroud)

Mar*_*ail 3

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