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

标签 python windows pip cpython

我正在尝试从 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' 

此外,我尝试过, 平台架构() 这给了:

('64bit', 'WindowsPE')

后来我搜索了我的site-packages 文件夹并找到了一些文件,例如__init__.cpython-36.pyc因此假设我使用的是 CPython 3.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.

sys 模块也可以在这里权衡,因为它同时具有 versionapi_version 例程。

>>> sys.version
'3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0]'
>>> sys.api_version
1013
>>> sys.version_info
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
>>> 

sys.version A string containing the version number of the Python interpreter plus additional information on the build number and compiler used. This string is displayed when the interactive interpreter is started. Do not extract version information out of it, rather, use version_info and the functions provided by the platform module.

sys.api_version The C API version for this interpreter. Programmers may find this useful when debugging version conflicts between Python and extension modules.

关于python - 我如何知道我使用的是哪个 CPython 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52914791/

相关文章:

python - 为什么我的笛卡尔积函数不起作用?

python - conda使用/usr/local/bin/python代替conda环境python

linux - 从批处理 Linux 到 Windows 的 awk 和 sed 命令。如何转换?

java - 从 Java 8 切换到 Java 11

python - __slots__ 中的 pip 安装失败,格式为 "ValueError: ' 与类变量冲突”

mysql - 升级到 Mavericks,现在 python MySQL DB 出错

python - 我可以恢复闭包包含 Python 循环的函数吗?

python - 在 python 中绘制带有邻接矩阵和坐标列表的连接图

windows - exe中的DllMain?

python - 使用 pip 安装私有(private) github 存储库时遇到问题