gpt4 book ai didi

python - 查找 Python Math 和 CMath 模块的特定版本

转载 作者:行者123 更新时间:2023-12-02 20:49:18 26 4
gpt4 key购买 nike

这个问题应该相对快速且简单。我只是想找出我拥有的 Python 的 math 和 cmath 包的版本。

不幸的是,我没有使用pip安装它们。我已经评论过this堆栈文章很有帮助(因为我之前不知道pip freeze)。然而,这两个软件包都不在列表中。

我尝试过谷歌并四处查看,但无济于事。我在解释器中尝试了以下操作:

import math
print math.__version # error
print math.version # error

我还尝试使用 python 的 help 命令并轻松浏览文档,但再次找不到有关如何检测我安装的版本的任何信息。

我不太确定还可以尝试什么。有什么想法吗?感谢你的宝贵时间!

最佳答案

你不能。 mathcmath 都不携带任何特定版本。它们与您正在使用的 Python 版本相关。


如果是因为你想检查某个函数是否存在,可以使用 3.2 中添加的 isfinite 。然后你可以使用 hasattr 来做到这一点:

print(hasattr(math, "isfinite"))

或使用sys.version_info:

has_infinite = sys.version_info >= (3, 2)
print(has_infinite)

由于我使用的是 Python 3.6,所以两者都输出 True

关于python - 查找 Python Math 和 CMath 模块的特定版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42866483/

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