{"id":21237,"date":"2023-09-28T13:52:07","date_gmt":"2023-09-28T13:52:07","guid":{"rendered":"https:\/\/linuxways.net\/?p=21237"},"modified":"2023-09-28T13:52:07","modified_gmt":"2023-09-28T13:52:07","slug":"how-to-find-python-version-on-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-find-python-version-on-linux-ubuntu\/","title":{"rendered":"How To Find Python Version on Linux\/Ubuntu?"},"content":{"rendered":"<p>Python is a popular programming language mainly used for Task Automation, Developing Data-Centric Software Systems, and Data Visualization. Python is used as a programming language for many software applications, so it is crucial to know which version of Python we are using. Knowing the Python Version helps us in using compatible tools and applications with the system.<\/p>\n<p>This article explains different methods to check the Python Version installed on Ubuntu.<\/p>\n<h2><strong>How To Find Python Version on Linux\/Ubuntu? <\/strong><\/h2>\n<p>Checking the Python version on Ubuntu helps us avoid any compatibility issues while installing any new software on a Linux\/Ubuntu machine. To find the installed Python Version on Ubuntu, use the Methods mentioned below:<\/p>\n<ul>\n<li>Using the Python3 Command<\/li>\n<li>Using the \u201csys module\u201d script<\/li>\n<li>Using \u201cplatform\u201d Command<\/li>\n<\/ul>\n<h2><strong>Method 1: Use the Python3 Command to Find Python Version on Linux\/Ubuntu<\/strong><\/h2>\n<p>The simplest method is to use the \u201cpython3\u201d command to check the Version details. Use the Python3 command along with the \u201c-V\u201d flag to display the version only:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">python3 <span class=\"re5\">-V<\/span><\/div><\/div>\n<p>The \u201c-V\u201d flag shows only the version of installed Python on Ubuntu:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"73\" class=\"wp-image-21238\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-1.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-1-300x30.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<h2><strong>Method 2: Use the \u201csys module\u201d Script to Find Python Version on Linux\/Ubuntu<\/strong><\/h2>\n<p>Python Version can also be checked using a Script. To use Script for checking the Python Version, create a file with the extension \u201c.sh\u201d:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">touch<\/span> python.sh<\/div><\/div>\n<p>The touch command will create the file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"292\" class=\"wp-image-21239\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-2.png 781w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-2-300x112.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-2-768x287.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/p>\n<p>Open the \u201cpython.sh\u201d file in a Text Editor like Nano:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">nano<\/span> python.sh<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"471\" class=\"wp-image-21240\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-3.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-3-300x192.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>In the \u201cpython.sh\u201d file, add the code below:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">import sys<br \/>\n<br \/>\nprint<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;Python Version: &quot;<\/span><span class=\"br0\">&#41;<\/span><br \/>\nprint<span class=\"br0\">&#40;<\/span>sys.version<span class=\"br0\">&#41;<\/span><\/div><\/div>\n<p>The \u201csys\u201d is a Library in Python used to provide information about the Python Interpreter:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"186\" class=\"wp-image-21241\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-4.png 751w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-4-300x74.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/p>\n<p>Once the above code is added, save the file using the \u201cctrl+o\u201d shortcut key and then close it using the \u201cctrl+x\u201d shortcut key. This will make the script file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"334\" class=\"wp-image-21242\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-5.png 767w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-5-300x131.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/p>\n<p>Make the Script File executable now by using the \u201cchmod +x\u201d command. The \u201c +x\u201d flag makes the file runnable:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">chmod<\/span> +x python.sh<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"339\" class=\"wp-image-21243\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-6.png 796w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-6-300x128.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-6-768x327.png 768w\" sizes=\"auto, (max-width: 796px) 100vw, 796px\" \/><\/p>\n<p>Once the Script File is executable, use the command below to execute it:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">python3 python.sh<\/div><\/div>\n<p>This will execute the file by running the code inside the script file and will print the Python Version as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"97\" class=\"wp-image-21244\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-7.png 731w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-7-300x40.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<h2><strong>Method 3: Use the \u201cplatform\u201d Command to Find the Python Version on Linux\/Ubuntu<\/strong><\/h2>\n<p>The \u201c<strong>platform<\/strong>\u201d command can also be used to show the current Python Version on Ubuntu. Use the command below with the platform command to print the current Python Version:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">python <span class=\"re5\">-c<\/span> <span class=\"st0\">&quot;import platform; print(platform.python_version())&quot;<\/span><\/div><\/div>\n<p>The \u201c-c\u201d flag is used to specify the configuration file or retrieve information from a config file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"893\" height=\"100\" class=\"wp-image-21245\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-8.png 893w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-8-300x34.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/09\/word-image-21237-8-768x86.png 768w\" sizes=\"auto, (max-width: 893px) 100vw, 893px\" \/><\/p>\n<p>This sums up how to find the Python version on Linux\/Ubuntu.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Knowing the Python Version helps developers install compatible software and tools for efficient and stable running of Ubuntu. Python Version on Ubuntu can be checked using either the \u201cpython3\u201d, using the \u201csys module\u201d in Script File, or using the \u201cplatform\u201d command. This article has explained in detail the use of all methods to check the Python Version in Ubuntu.<\/p>","protected":false},"excerpt":{"rendered":"<p>The Python Version on Ubuntu can be checked using either the \u201cpython3\u201d command, using the \u201csys module\u201d in Script File, or using the \u201cplatform\u201d command.<\/p>","protected":false},"author":110,"featured_media":21433,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-21237","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21237"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21237\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21433"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}