Short command to check python version in Linux or Window?

Dung Do Tien Feb 02 2022 43

Hello Guys,

I just updated my computer from window 10 to 11 and I have a small project with Python. 

Today I clone that project from GitHub to my computer. And I want to check the current Python version installed on my computer and I try :

python -v command in cmd and I got the result:

import _frozen_importlib # frozen
import _imp # builtin
import '_thread' # <class '_frozen_importlib.BuiltinImporter'>
import '_warnings' # <class '_frozen_importlib.BuiltinImporter'>
import '_weakref' # <class '_frozen_importlib.BuiltinImporter'>
import '_io' # <class '_frozen_importlib.BuiltinImporter'>
import 'marshal' # <class '_frozen_importlib.BuiltinImporter'>
import 'nt' # <class '_frozen_importlib.BuiltinImporter'>
import 'winreg' # <class '_frozen_importlib.BuiltinImporter'>
import '_frozen_importlib_external' # <class '_frozen_importlib.FrozenImporter'>
# installing zipimport hook
import 'time' # <class '_frozen_importlib.BuiltinImporter'>
import 'zipimport' # <class '_frozen_importlib.FrozenImporter'>
# installed zipimport hook
# C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\encodings\__pycache__\__init__.cpython-39.pyc matches C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\encodings\__init__.py

I don't know what is this.

I tried with python version command and I got another error:

python: can't open file 'C:\Users\conta\version': [Errno 2] No such file or directory

I am checking in window 11, How can I find the current Python version in Window?

Thank you for any help!!

Have 2 answer(s) found.
  • S

    SAGAR Feb 04 2022

    To check version of Python in Window or Linux you can use python --version python -V or python -VV commands, see below:

    C:\Users\conta>python --version
    Python 3.9.10
    
    C:\Users\conta>python -V
    Python 3.9.10
    
    C:\Users\conta>python -VV
    Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)]
    
    C:\Users\conta>

    I hope this is the answer for your question.

  • A

    Anil Pardeshi Feb 04 2022

    1. With comand you can use some ways below:

    $ python --version
    Python 3.9.10
    
    $ python -V
    Python 3.9.10
    
    $ python3 --version
    Python 3.9.10
    
    $ python3 -V
    Python 3.9.10

    2. In your code, you can use sys or platform modules to get current version of Python.

    import sys
    print(sys.version)

    #Output: 

    3.8.2 (default, Mar 13 2020, 10:14:16) 
    [GCC 9.3.0]

    Or

    import platform
    print(platform.python_version()) #Output: 3.8.2

    I hope this answer will helpful for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close