首页 > 解决方案 > 在 Django 中导入 Sentry_sdk 失败

问题描述

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

第 301 行,在模块导入 sentry_sdk ModuleNotFoundError: No module named 'sentry_sdk' unable to load app 0 (mountpoint='') (callable not found or import error)

我复制了文档,我想知道为什么会这样。有没有人遇到过这个问题?我的 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",
)

标签: pythondjangosentry

解决方案


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


推荐阅读