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.
asked Jan 18, 2012 at 21:43
6
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)
answered Jan 3, 2014 at 4:47
pzppzp
6,1811 gold badge27 silver badges38 bronze badges
6
Python 2.5+:
python --version
Python 2.4-:
python -c 'import sys; print(sys.version)'
mcandre
22k19 gold badges87 silver badges145 bronze badges
answered Jan 18, 2012 at 21:45
AbbasAbbas
6,6704 gold badges35 silver badges49 bronze badges
5
At a command prompt type:
python -V
Or if you have pyenv:
pyenv versions
answered Jan 18, 2012 at 21:45
Brian WillisBrian Willis
22.1k9 gold badges46 silver badges50 bronze badges
0
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
answered May 31, 2015 at 11:17
user2099484user2099484
4,3092 gold badges20 silver badges9 bronze badges
1
When I open Python (command line)
the first thing it tells me is the version.
answered Jan 18, 2012 at 21:47
poypoy
9,8239 gold badges45 silver badges72 bronze badges
2
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
answered May 26, 2016 at 13:34
wsdzbmwsdzbm
2,7993 gold badges23 silver badges26 bronze badges
In short:
Type
python
in a command prompt
Simply open the command prompt (Win + R) and type cmd
and in the command prompt then typing python
will give you all necessary information regarding versions:
mar10
13.9k5 gold badges38 silver badges64 bronze badges
answered Dec 15, 2016 at 9:48
2
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 the 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.
answered Dec 23, 2018 at 3:24
dahianadahiana
1,1212 gold badges9 silver badges10 bronze badges
1
>>> 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))"
answered Jul 22, 2016 at 7:28
BaczekBaczek
1,1391 gold badge13 silver badges22 bronze badges
Use
python -V
or
python --version
NOTE: Please note that the «V» in the python -V
command is capital V. python -v
(small «v») will launch Python in verbose mode.
answered Nov 21, 2015 at 0:47
Yogesh YadavYogesh Yadav
4,3496 gold badges32 silver badges38 bronze badges
0
You can get the version of Python by using the following command
python --version
You can even get the version of any package installed in venv using pip freeze
as:
pip freeze | grep "package name"
Or using the Python interpreter as:
In [1]: import django
In [2]: django.VERSION
Out[2]: (1, 6, 1, 'final', 0)
answered May 17, 2015 at 6:13
PoojaPooja
1,23414 silver badges17 bronze badges
To check the Python version in a Jupyter notebook, you can use:
from platform import python_version
print(python_version())
to get version number, as:
3.7.3
or:
import sys
print(sys.version)
to get more information, as
3.7.3 (default, Apr 24 2019, 13:20:13) [MSC v.1915 32 bit (Intel)]
or:
sys.version_info
to get major, minor and micro versions, as
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
answered Jan 9, 2020 at 19:25
nucsit026nucsit026
6327 silver badges16 bronze badges
On Windows 10 with Python 3.9.1, using the command line:
py -V
Python 3.9.1
py --version
Python 3.9.1
py -VV
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit
(AMD64)]
answered Sep 12, 2016 at 15:04
SamSam
2133 silver badges7 bronze badges
2
If you are already in a REPL window and don’t see the welcome message with the version number, you can use help() to see the major and minor version:
>>>help()
Welcome to Python 3.6's help utility!
...
answered Feb 15, 2019 at 12:41
OrigamiEyeOrigamiEye
7501 gold badge8 silver badges27 bronze badges
Typing where python
on Windows into a Command Prompt may tell you where multiple different versions of python are installed, assuming they have been added to your path.
Typing python -V
into the Command Prompt should display the version.
answered Feb 8, 2020 at 5:07
Pro QPro Q
4,1044 gold badges38 silver badges86 bronze badges
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.
answered Aug 13, 2017 at 22:45
1
To verify the Python version for commands on Windows, run the following commands in a command prompt and verify the output:
c:> python -V
Python 2.7.16
c:> py -2 -V
Python 2.7.16
c:> py -3 -V
Python 3.7.3
Also, to see the folder configuration for each Python version, run the following commands:
For Python 2, 'py -2 -m site'
For Python 3, 'py -3 -m site'
answered Apr 2, 2019 at 17:16
For me, opening CMD and running
py
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.
answered Dec 29, 2015 at 12:42
1
Just create a file ending with .py and paste the code below 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 a terminal:
ll /usr/bin/python*
On Windows, run in a command prompt:
dir %LOCALAPPDATA%ProgramsPython
answered Mar 19, 2018 at 13:24
1
There are two simple ways to check for the version of Python installed.
Run any of the codes on the command prompt:
python -v
or
python --version
answered Jul 28, 2022 at 4:43
Happy N. MondayHappy N. Monday
1831 gold badge2 silver badges6 bronze badges
For the latest versions please use the below command for the python version
py -V
answered Aug 1, 2022 at 3:56
Jb-99Jb-99
1359 bronze badges
Mostly usage commands:
python -version
Or
python -V
answered Jun 8, 2020 at 12:23
KittoMiKittoMi
4135 silver badges18 bronze badges
The default Python version and the paths of all installed versions on Windows:
py -0p
One-Liners:
❯❯ python -V | cut -c8-
3.11.0
❯❯ ~ python -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python --version
Python 3.11.0
❯❯ ~ py --list
-V:3.11 * Python 3.11 (64-bit)
-V:3.10 Python 3.10 (64-bit)
-V:3.9 Python 3.9 (64-bit)
❯❯ ~ py -V
Python 3.11.0
❯❯ ~ py -VV
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ py --version
Python 3.11.0
❯❯ ~ py -0p
-V:3.11 * W:Windows 10Python311python.exe
-V:3.10 W:Windows 10Python310python.exe
-V:3.9 C:Program FilesPython39python.exe
❯❯ ~ python -c 'import sys; print(".".join(sys.version.split(".")[0:2]))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version)'
3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
❯❯ ~ python -c 'import sys; print((str(sys.version_info.major) +"."+ str(sys.version_info.minor)))'
3.11
❯❯ ~ python -c 'import sys; print(sys.version_info)' sys.version_info(major=3, minor=11, micro=0, releaselevel='final', serial=0)
❯❯ ~ python -c 'import platform; print(platform.python_version()[:-2])'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version())'
3.11.0
❯❯ ~ python -c 'import platform; print("{0[0]}.{0[1]}".format(platform.python_version_tuple()))'
3.11
❯❯ ~ python -c 'import platform; print(platform.python_version_tuple())'
('3', '11', '0')
answered Dec 5, 2021 at 11:44
SzczerskiSzczerski
6999 silver badges8 bronze badges
For bash scripts this would be the easiest way:
# In the form major.minor.micro e.g. '3.6.8'
# The second part excludes the 'Python ' prefix
PYTHON_VERSION=`python3 --version | awk '{print $2}'`
echo "python3 version: ${PYTHON_VERSION}"
python3 version: 3.6.8
And if you just need the major.minor
version (e.g. 3.6
) you can either use the above and then pick the first 3 characters:
PYTHON_VERSION=`python3 --version | awk '{print $2}'`
echo "python3 major.minor: ${PYTHON_VERSION:0:3}"
python3 major.minor: 3.6
or
PYTHON_VERSION=`python3 -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))'`
echo "python3 major.minor: ${PYTHON_VERSION}"
python3 major.minor: 3.6
answered Jan 8, 2021 at 12:31
as of 2022, to check what version you’re on you can do python --version
answered Jul 31, 2022 at 0:11
Open a command prompt window (press Windows + R, type in cmd
, and hit Enter).
Type python.exe
answered Jun 29, 2017 at 7:28
ErinaErina
811 gold badge2 silver badges13 bronze badges
1
In this article, we will get to know the current version of the Python interpreter in the system. Getting the version of the interpreter is really important as the python interpreter is widely used throughout the industries for computer programming and source coding. It takes an interactive command and executes it.
As the interpreter is the one which takes the code and helps in execution. Sometimes the old version of the interpreter-making command doesn’t work properly and as we know the language python comes with frequent update vision with some added new features, so the user must update the interpreter with the latest release version.
How to check what version of Python?
To get the Version of the python Interpreter, they are listed as follows:
- Using sys.version method
- Using python_version() function
- Using Python -V command
Method 1. Using sys.version method:
For this method, the user needs to import the sys library and from sys.version command which will return the user’s current python version in the use. For this method, the user must open the Python shell and write the following command as given below, with this command the user will get the current working version of the python interpreter in the form of a string.
Here is some step that the user must follow to get the currently running version of the python interpreter:
- Open cmd/terminal/windows powershell
- Write ‘python’ and press enter key to move into Python interpreter
- Write the same command given in the input box below, and in the result, the user will get the current interpreter version.
Python3
import
sys
print
(
"User Current Version:-"
, sys.version)
Output:
Method 2. Using python_version() function
This function is accessible by importing the platform library and will always return a string of the running user’s python version. For better understanding one can go with the following steps:-
- Open cmd/terminal/windows powershell
- Write ‘python’ and press enter key to move into the Python interpreter
- Now, write the same command as mentioned below in the code box given, and press enter, with this it will return the current python interpreter version in the form of a string.
Python3
from
platform
import
python_version
print
(
"Current Python Version-"
, python_version())
Output:
Method 3. Using python -V command
This method is one of the simplest methods among all other methods as in this method users get the current python version with one of the inbuilt commands present in python.
Here are some steps that the user must follow to get its current running version of the python interpreter:-
- Open cmd/terminal/windows powershell
- Now, write the same command as mention below in the code box given, and press enter, with this it will return the current python interpreter version in the form of a string.
python -V
Output:
Download Article
A step-by-step guide on checking your Python version
Download Article
This wikiHow teaches you how to find which version of Python is installed on your Windows or macOS computer.
-
1
Open Windows Search. If you don’t already see a search box in the taskbar, click the magnifying glass or circle next to
, or press ⊞ Win+S.
-
2
Type python into the search bar. A list of matching results will appear.
Advertisement
-
3
Click Python [command line]. This opens a black terminal window to a Python prompt.
-
4
Find the version in first line. It’s the number right after the word “Python” at the top-left corner of the window (e.g. 2.7.14).
Advertisement
-
1
Open a Terminal window on your Mac. To do this, open the Applications folder in Finder, double-click the Utilities folder, then double-click Terminal.
-
2
Type python -V at the prompt (V uppercase).
-
3
Press ⏎ Return. The version number will appear on the next line after the word “Python” (e.g. 2.7.3).
Advertisement
Add New Question
-
Question
I downloaded Python 3.7 but when I check it says that the version is 2.7. What should I do ? (I tried reinstalling it.)
faith daniel
Community Answer
To prevent further hassle, just download the 3.x version or the latest version from the Python website (python.org).
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Thanks for submitting a tip for review!
About This Article
Article SummaryX
To check which version of Python is installed on your Windows PC, start by opening the Windows Search and typing “Python” into the search bar. When the list of matching results comes up, click “Python” to open a black terminal window to a Python prompt. In the top-left corner of the window, you’ll see a number right after the word “Python,” which is the version that you’re currently running. To learn how to find the version of Python on your Mac, keep reading!
Did this summary help you?
Thanks to all authors for creating a page that has been read 367,144 times.
Is this article up to date?
Before learning how to check the python version, we should first understand Python and its versions briefly.
Python is an object-oriented, high-level interpreted scripting language.
Let us discuss some of the various important points regarding the Python programming language :
- Python programming language is a highly readable language making it easy to understand for new coders.
- ABC programming language can be considered the predecessor of the Python programming language. Modula-3 also has some influence on the Python programming language.
- The Python programming language was developed by Guido Van Rossum in the Netherlands in 1991.
- Python language is widely used in various technical fields such as Artificial Intelligence (AI), Machine Learning (ML), Scientific Calculation, Desktop Application, Web Development (using Django, and Flask framework, etc.) Mobile Application Development, etc.
Let us learn how to check the python version using the command line and scripts.
Check Python Version: Command-Line
Let us first learn how to check the python version using the various command-line commands used in different operating systems.
i) Windows:
In Windows operating systems, we can use the command python —version to check the python version.
The steps to check the python version in Windows are very simple:
- Open the Windows command prompt or Windows Powershell, and enter the following command on the shell :
If we have a Python interpreter installed on the Windows operating system then the command will show the version like :
Output :
Note :
- The version number may differ, but if the Python interpreter is installed in a system, it will similarly show the version.
- We can also search for Python present on the system. We can press the Windows key to launch the search menu and then we can type Python. If the system has installed Python, it will show the Python version.|
ii) MacOS :
In macOS operating systems, we can use the same command, python —version, to check the python version.
The steps to check the python version in macOS are very simple:
- Open the macOS Terminal, and enter the following command on the shell or terminal :
If we have a Python interpreter installed on the macOS operating system, then the command will show the version like :
Output :
iii) Linux :
In Linux operating systems, we can use the same command, python —version to check the python version.
The steps to check the python version in Linux are very simple:
- Open the Linux terminal or shell and type the following command :
If we have a Python interpreter installed on the Linux operating system, then the command will show the version like :
Output :
Note:
We can use the commands such as python —version or python -v or python -VV. All of these commands will provide a similar result. The -VV option is a new command added since Python 3.6. Which can be used for detailed information than -V or —version.
Check Python Version: Script
Let us now learn how to check the python version using scripts.
We can use the sys module or the platform module of the standard library to check the python version in various operating systems. The script will be the same for all operating systems such as Windows, Mac, Linux, etc.
The script is very useful for checking the python version even tho we have various versions of Python installed on our system. Let us see the script and its related information.
i) Various information string: sys.version :
We can use the .version method in the sys (system) module to print the version of the Python interpreter installed on the system. The sys. version method returns a string that contains the version number of the Python interpreter installed in the system. It also returns additional information about the build number and the compiler used.
let us now look at the script :
import sys print(sys.version)
Output :
3.7.6 (default, July 4, 2022, 20:13:13) [Clang 9.1.0 (clang-902.0.39.2)]
ii) Tuple of version numbers: sys.version_info :
We can also use the .version_info method in the sys (system) module to print the version of the Python interpreter installed on the system. The sys.version_info method returns a tuple containing five components of the Python interpreter version number: the major version release number, the minor version release number, the micro version release number, the release level, and the serial number.
let us now look at the script :
import sys print(sys.version_info)
Output :
sys.version_info(major=3, minor=9, micro=2, releaselevel='final', serial=0)
Note :
The release level element is a string, and the other output elements are integers.
iii) Version number string: platform.python_version() :
We can also use the .python_version() method present in the platform module to print the version of the Python interpreter installed on the system. The platform.python_version() method returns a string in the form major.minor.patchlevel. The string denotes the major release number then the minor release number, and then the patch level, each separated using a dot(.)
let us now look at the script:
import platform print(platform.python_version())
Output :
The script is handy when we want to check the Python interpreter version number as a simple string only.
iv) Tuple of version number strings: platform.python_version_tuple() :
We can also use the .python_version_tuple() method present in the platform module to print the version of the Python interpreter installed on the system. The platform.python_version_tuple() method returns a tuple in the form ‘major’, ‘minor’, ‘patchlevel’. The tuple denotes the major release number, then the minor release number, and then the patch level, each separated using a comma(,). Each element of the tuple is in the form of a string.
let us now look at the script:
import platform print(platform.python_version_tuple())
Output :
What are the Different Python Versions?
We have already discussed what Python programming language is and how to check the python version, let us briefly discuss the various popular versions of the Python programming language.
- The first version of Python was released in 1994 named Python 1.0. Python 1.0 had various features like lambda function, map, filter, reduce, etc.
- The second version of Python was released in 2000, with many major new features such as garbage collection systems, list comprehensions, etc.
- The third and latest major Python version release was released in 2008. This version of Python (Python 3.0) is also known as Py3K.
Refer to the below-specified table to check the various Python interpreter versions and their release dates.
Python Versions | Release Date |
---|---|
Python 1.0 | January 1994 |
Python 1.5 | December 31, 1997 |
Python 1.6 | September 5, 2000 |
Python 2.0 | October 16, 2000 |
Python 2.1 | April 17, 2001 |
Python 2.2 | December 21, 2001 |
Python 2.3 | July 29, 2003 |
Python 2.4 | November 30, 2004 |
Python 2.5 | September 19, 2006 |
Python 2.6 | October 1, 2008 |
Python 2.7 | July 3, 2010 |
Python 3.0 | December 3, 2008 |
Python 3.1 | June 27, 2009 |
Python 3.2 | February 20, 2011 |
Python 3.3 | September 29, 2012 |
Python 3.4 | March 16, 2014 |
Python 3.5 | September 13, 2015 |
Python 3.6 | December 23, 2016 |
Python 3.7 | June 27, 2018 |
Python 3.8 | October 14, 2019 |
How to Upgrade to a Newer Version?
We can easily upgrade to the latest or newer version of the Python interpreter by simply going to the (visiting) Python downloads page and downloading the latest version.
What if Your Computer has Multiple Python Versions Installed?
We can have multiple Python interpreter versions installed on our system. We can run a particular python program (or python script) using the specified Python interpreter version.
For example, if we have Python 2.6 and Python 3.6 installed on our system, then we can run a file (let’s say program.py) using both interpreters.
Example : (For Python 3.6)
Example : (For Python 2.6)
Python 2 vs Python 3
Both Python 2 and Python 3 are very popular interpreters, let us discuss some of the major differences between both releases.
Python 2 | Python 3 |
---|---|
Python 2 was released in 2000. | Python 3 was released in 2008. |
Python 2 interpreter considers print as a statement but not a function. | Python 3 interpreter considers print() as a function. |
The strings are by default stored as UNICODE characters in Python 2. | The strings are by default stored as ASCII characters in Python 2. |
The division of two integral values in Python 2 results in another integral value. For example, 7/2 yields 3. | The division of two integral values in Python 3 results in a floating-point value. For example, 7/2 yields 3.5 |
Exception in Python 2 was dealt with in the enclosed notations. | Exceptions in Python 3 are enclosed in parentheses. |
We used the xrange() function for iteration in Python 2. | We use the range() function for iteration in Python 3. |
Python 2 is not longer in use since the year 2020. | Python 3 is more popular than Python 3 but in some places, we still use Python 2. |
With some effort, we can port the Python 2 code to Python 3. | Python 3 has no backward compatibility with the previous version i.e. Python 2.} |
Learn More
To learn more about the Python Programming Language, refer to the articles :
- Install Python on Windows
- How to Install Python on Linux?
- How to Install Python on macOS?
Conclusion
- In Windows operating systems, we can use the command python —version to check the python version. We just need to open the Windows command prompt, or Windows Powershell, and enter the command.
- In macOS operating systems and Linux operating systems, we can use the same command python —version to check the python version.
- We can use the sys. version method present in the sys (system) module to print the version of the Python interpreter installed on the system.
- The sys. version method returns a string that contains the version number of the Python interpreter installed in the system.
- The sys.version_info method returns a tuple that contains a major version number, the minor number, the micro version number, the release level, and the serial number.
- The platform.python_version() method returns a string in the form major.minor.patchlevel.
- We can also use the .python_version_tuple(). The platform.python_version_tuple() method returns a tuple in the form ‘major’, ‘minor’, ‘patchlevel’.
- The tuple denotes the major release number, the minor release number, and then the patch level separated using a comma(,). Each element of the tuple is in the form of a string.
- We can have multiple Python interpreter versions installed on our system. We can run a particular python program (or python script) using the specified Python interpreter version.