python - 在 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",
)
解决方案
你确定你已经安装sentry
在你的环境中了吗?确保您pip install sentry-sdk
在运行代码的同一环境中运行
推荐阅读
- c++ - 无法创建跳舞的星球图案
- r - 如何在R中将两行的值合并在一起
- docker - docker构建一个安装了httpd和memcached的镜像,但是当使用这个镜像运行一个容器时,memcached没有启动
- javascript - 变量未定义,除非包含在 setTimeout 中
- c# - EmguCV 选择多边形外的区域
- python - 将具有 dicts 作为值的 dicts 列表转换为 ML 特征
- html - 在反应中从内容可编辑的 div 获取输入
- c# - Youtube Explode 与 Azure Speech to Text
- vue.js - 在 vb-popover 中添加切换属性以进行触摸
- javascript - 遇到 PHP 错误 严重性:通知消息:未定义的偏移量:1 文件名:views/view_performance.php 行号:28