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.
--version may also work (introduced in version 2.5)
python -c 'import sys; print(sys.version)'
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)
At a command prompt type:
Or if you have pyenv:
When I open
Python (command line) the first thing it tells me is the version.
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
In : import sys In : 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 : sys.version_info sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0) In : sys.version_info >= (2,7) Out: True In : sys.version_info >= (3,) Out: False