根据此处的讨论,我正在尝试在我的网站上运行分析过程,但遇到了此错误。这是完整的堆栈跟踪:
C:\Users\Alex\Anaconda3\envs\mysite\python.exe C:/Users/Alex/Desktop/mysite/profile.py
Traceback (most recent call last):
File "C:/Users/Alex/Desktop/mysite/profile.py", line 6, in <module>
app = ProfilerMiddleware(app)
File "C:\Users\Alex\Anaconda3\envs\mysite\lib\site-packages\werkzeug\contrib\profiler.py", line 80, in __init__
raise RuntimeError('the profiler is not available because '
RuntimeError: the profiler is not available because profile or pstat is not installed.
起初我认为这是 Windows 错误之一,我尝试在我的 Mac 上做同样的事情。同样的错误。
唔。我在代码中找到了负责任的导入语句werkzeug
:
try:
try:
from cProfile import Profile
except ImportError:
from profile import Profile
from pstats import Stats
available = True
except ImportError:
available = False
这会导致稍后在第 79 行出现故障:
if not available:
raise RuntimeError('the profiler is not available because '
'profile or pstat is not installed.')
所以我想这意味着我缺少这些模块之一?但它们是核心 Python 模块AFAIK!
我打开一个IPython
控制台,启动到负责的conda
虚拟环境,果然:
这是怎么回事?