我如何知道我使用的是哪个 CPython 版本?

How do I find out which CPython version I am using?

我正在尝试从 Unofficial Windows Binaries for Python Extension Packages 安装 OpenCV。

我下载了以下文件:opencv_python‑3.4.3‑cp37‑cp37m‑win_amd64.whl, 当我这样做时 pip install "opencv_python‑3.4.3‑cp37‑cp37m‑win_amd64.whl",一条错误消息弹出。

错误opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.

根据我在谷歌搜索和 SO-ing 后的理解,这是一个问题,因为 CPython 构建之间的 不匹配 - 在下载的 wheel 文件之间以及我系统上的 Python 环境。

因此,我尝试寻找方法来确定我的系统上是哪个 CPython 版本,但失败了。

到目前为止我尝试了什么:

import platform
platform.python.implementation()

给出了:

'CPython' 

此外,我尝试过, platform.architecture() 这给了:

('64bit', 'WindowsPE')

我后来只是搜索了我的 site-packages 文件夹,发现了一些文件,例如 __init__.cpython-36.pyc,因此假设我使用的是 CPython3.6

是否有更多基于编程的方法通过终端检查相同内容?

感谢任何形式的帮助。 TIA.

platform 模块将提供 python 版本使用:

>>> import platform
>>> platform.python_version()
'3.6.6'

虽然简单地说 运行 python 从命令行应该提供一个 header 也给你这个信息。

$ python
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.

它也可能与您的 python 的特定 ABI 标签有关。也许你的不是 cp37m,其中 'm' 代表使用 pymalloc 编译。

要获取 ABI 标签,您可以 pip install wheel 然后以编程方式获取它:

>>> from wheel.pep425tags import get_abi_tag
>>> get_abi_tag()
'cp37m'