pythonwindowspipcpython

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


I am trying to install OpenCV from Unofficial Windows Binaries for Python Extension Packages.

I downloaded the following file : opencv_python‑3.4.3‑cp37‑cp37m‑win_amd64.whl, and when I did pip install "opencv_python‑3.4.3‑cp37‑cp37m‑win_amd64.whl", an error message popped.

The error : opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.

From what I understood after some googling and SO-ing, this is an issue due to a mismatch between the CPython builds - between the downloaded wheel file and the Python environment on my system.

Therefore, I tried finding ways to determine which CPython version is on my system, but failed.

What I tried so far:

import platform
platform.python.implementation()

Which gave:

'CPython' 

Further, I tried, platform.architecture() which gave:

('64bit', 'WindowsPE')

I later just scoured through my site-packages folder and found somefiles such as __init__.cpython-36.pyc, hence assuming that I am using CPython 3.6.

Is there a more programming based method to check the same through the terminal?

Any kind of help is appreciated. TIA.


Solution

  • Display supported CPython series:

    python3 -m pip install pyversion-info
    python3 -c 'from pyversion_info import VersionDatabase; vd = VersionDatabase.fetch(); print(vd.cpython.supported_series())'
    

    This gives for example the following output:

    ['3.8', '3.9', '3.10', '3.11', '3.12']
    

    Note that this uses pyversion-info which requires Python 3.7 or higher. See pyversion-info for more info.