Advertisement
Advertisement


Which version of Python do I have installed?


Question

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 the latest version of Python.

2019/11/24
1
467
11/24/2019 4:58:39 PM

Accepted Answer

python -V

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

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

2014/04/04
631
4/4/2014 4:22:23 PM

Python 2.5+:

python --version

Python 2.4-:

python -c 'import sys; print(sys.version)'
2015/08/07

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)
2019/11/24

At a command prompt type:

python -V

Or if you have pyenv:

pyenv versions
2019/08/15

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

2012/01/18

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
2019/11/24

Source: https://stackoverflow.com/questions/8917885
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]