gpt4 book ai didi

python-3.x - Python (c) 配置文件 : Error importing SortKey from pstats

转载 作者:行者123 更新时间:2023-12-04 09:57:26 33 4
gpt4 key购买 nike

我正在尝试阅读 Python 配置文件(rs)的文档。我在 Win10 笔记本电脑上的 Anaconda 中使用 Python 3.6。

https://docs.python.org/3/library/profile.html

import cProfile
import re
cProfile.run('re.compile("foo|bar")')

根据文档,这执行没有问题。

然而,
import pstats
from pstats import SortKey

导致此错误消息:
ImportError: cannot import name 'SortKey'

有一个 class SortKey(str, Enum)在这个版本的 pstats :
https://github.com/python/cpython/blob/master/Lib/pstats.py

但是,当我查看本地 pstats.py 时文件,我没有那个类,例如 ~\AppData\Local\Continuum\anaconda3\envs\py36\Lib\pstats.py与(cPython)非常不同 pstats.py .

我想我错过了一些明显的东西......

最佳答案

问题是 Python 3.6 与 Python 3.7。

3.6,没有 SortKey :
https://docs.python.org/3.6/library/profile.html

3.7,与SortKey :
https://docs.python.org/3.7/library/profile.html

在文档 URL 中使用整数默认为最新版本,例如3.7,当我需要 3.6 的文档时。

关于python-3.x - Python (c) 配置文件 : Error importing SortKey from pstats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53490248/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com