-->

Which version of Python do I have installed?

2019-01-20 21:42发布

问题:

I have to run a Python script on a Windows server. How can I know which version of Python I have, and does it even really matter? I was thinking of updating to latest version of Python.

回答1:

python -V

http://docs.python.org/using/cmdline.html#generic-options

--version may also work (introduced in version 2.5)



回答2:

Python 2.5+:

python --version

Python 2.4-:

python -c 'import sys; print(sys.version)'


回答3:

in a Python IDE just copy and paste in the following code and run it (the version will come up in the output area)

import sys
print(sys.version)


回答4:

At a command prompt type:

python -V


回答5:

When I open Python (command line) the first thing it tells me is the version.



回答6:

Although the question is "which version am I using?", this may not actually be everything you need to know. You may have other versions installed and this can cause problems, particularly when installing additional modules. This is my rough-and-ready approach to finding out what versions are installed:

updatedb                  #be in root for this
locate site.py            #all installations I've ever seen have this

The output for a single Python installation should look something like this:

/usr/lib64/python2.7/site.py  
/usr/lib64/python2.7/site.pyc
/usr/lib64/python2.7/site.pyo

Multiple installations will have output something like this:

/root/Python-2.7.6/Lib/site.py
/root/Python-2.7.6/Lib/site.pyc
/root/Python-2.7.6/Lib/site.pyo
/root/Python-2.7.6/Lib/test/test_site.py
/usr/lib/python2.6/site-packages/site.py
/usr/lib/python2.6/site-packages/site.pyc
/usr/lib/python2.6/site-packages/site.pyo
/usr/lib64/python2.6/site.py
/usr/lib64/python2.6/site.pyc
/usr/lib64/python2.6/site.pyo
/usr/local/lib/python2.7/site.py
/usr/local/lib/python2.7/site.pyc
/usr/local/lib/python2.7/site.pyo
/usr/local/lib/python2.7/test/test_site.py
/usr/local/lib/python2.7/test/test_site.pyc
/usr/local/lib/python2.7/test/test_site.pyo


回答7:

In [1]: import sys

In [2]: sys.version
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

In [3]: sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)

In [4]: sys.version_info >= (2,7)
Out[4]: True

In [5]: sys.version_info >= (3,)
Out[5]: False


回答8:

python -V

or

python --version

NOTE :- Please note that the "V" in python-V command is capital V. python -v (small "v") will launch Python in verbose mode.



回答9:

In Short :

Type python in command prompt

Simply open command prompt (Clr + R) and type cmd and and in command prompt then typing python will give you all necessary info regarding versions



回答10:

you can get version of python by using following command

python --version

You can even get version of any package installed in venv using pip freeze as

pip freeze | grep "package name"

or using python interpreter as

In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)


回答11:

>>> import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))
3.5

so from the command line:

python -c "import sys; print('{0[0]}.{0[1]}'.format(sys.version_info))"


回答12:

just start it at terminal

python
sergio@tarro:
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 


回答13:

Just create a file ending with .py and paste the code bellow into and run it.

#!/usr/bin/python3.6

import platform
import sys

def linux_dist():
  try:
    return platform.linux_distribution()
  except:
    return "N/A"

print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_dist(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
))

If several Python interpreter versions are installed on a system, run the following commands.

On Linux run in terminal:

ll /usr/bin/python*

On Windows run in command prompt:

dir %LOCALAPPDATA%\Programs\Python


回答14:

For me. open CMD and run py it will show something like Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.



回答15:

On Windows 10 with Python 3.6

    python

Python 3.6.0a4 (v3.6.0a4:017cf260936b, Aug 16 2016, 00:59:16) [MSC v.1900 64 bit (AMD64)] on win32


    python -V

Python 3.6.0a4


    python --version

Python 3.6.0a4


回答16:

Open a command prompt window (press Windows+R, type in cmd, and hit enter). Type python.exe



回答17:

If you have Python installed then the easiest way you can check the version number is by typing "python" in your command prompt. It will show you the version number and if it is running on 32 bit or 64 bit and some other information. For some applications you would want to have a latest version and sometimes not. It depends on what packages you want to install or use.



回答18:

I have Python 3.7.0 on Windows 10. This is what worked for me in the command prompt and git bash:

To run Python and check version:

py

To only check which version you have:

py --version

or

py -V    #make sure it is a capital V

Note: python, python --version, python -V,Python, Python --version, Python -V did not work for me. Posted this answer in case others had the same issue.