我如何知道 Google Colab 中库的版本?为 Z3 尝试

How can I know the version of a library in Google Colab? Trying it for Z3

我知道我可以在 Google Colab 中手动安装具体版本的库(参见 When I install older version of scikit-learn in Google Colab, it still import the newest version)。

但是,我怎么知道我使用的是哪个版本的库?我想知道我正在使用哪个版本的 Z3

我测试了以下内容:

pip install z3-solver
import z3
z3 -version

但我收到以下错误:name 'version' is not defined

在我的 (Unix) 机器上,只需询问:z3 -version(参见 Z3 -smt2 -in: Get Z3 version

这个问题可以扩展到任何库。

你应该使用 dunder 表示法

z3.__version__

编辑 - 用于 pip 包 z3-solver

你应该使用

import z3
z3.get_version_string()

如所见here

I am trying to know which version of Z3 I am using.(...)This question is extensible to any library.

然后不依赖库来报告,而是pip。您可以简单地指示 piplist 所有已安装的模块并找到感兴趣的版本,即

pip install z3-solver
pip list