Search code examples
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

  • The platform module will provide the python version using:

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

    Although that said simply running python from the command line should provide a header which gives you this information as well.

    $ 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.
    

    The sys module can weigh in here as well, as it has both version and api_version routines.

    >>> 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.