{"id":173,"date":"2020-09-26T12:59:02","date_gmt":"2020-09-26T12:59:02","guid":{"rendered":"https:\/\/dft.wiki\/?p=173"},"modified":"2026-06-09T15:07:52","modified_gmt":"2026-06-09T19:07:52","slug":"running-python-programs-in-linux-console","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=173","title":{"rendered":"Running Python Programs in Linux Console"},"content":{"rendered":"<p>If you are discovering or studying Python, you may stay in the interpreter environment to perform all the tasks you want. But if you make a program that has a real function and you want it to run like any other program on the system, for example in your Linux console, here is how it works.<\/p>\n<p>First, you have to know that Python 2 and 3 are not compatible. So, if you wrote your program in version 2, it will not work in version 3, and the opposite is also true.<\/p>\n<p>Knowing that your program was written in version 3, this is the command:<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-136\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-6-1.png\" alt=\"\" \/><\/figure>\n<p>Note: The first line lists the .py files in the current directory, the second line shows the files. The third line is the command used to run one of the files, and the last two lines are the program&#8217;s output.<\/p>\n<p>If the program is written in version 2, you can replace the number 3 with 2, or just remove the number entirely since 2 is the default (this may explain any problems you encounter while running your programs):<\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" class=\"wp-image-137\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2020\/09\/image-7-1.png\" alt=\"\" \/><\/figure>\n<p>Note: In the example above the command is correctly issued, but the errors from the third line onward are because the program was actually written in version 3. This is the type of error you may get even if there is no code error in the program.<\/p>\n<p><strong>Interactive Mode<\/strong> &#8211; Instead of exiting when the program finishes, it will start an interactive session, which is very useful for debugging and prototyping.<\/p>\n<pre>python <strong>-i<\/strong> fileName.py<\/pre>\n<p>Using <strong>Python Modules<\/strong> [<a href=\"https:\/\/docs.python.org\/3\/py-modindex.html\">Link<\/a>] for better productivity:<\/p>\n<pre>python <strong>-m<\/strong> SimpleHTTPServer 80<\/pre>\n<p>OR<\/p>\n<pre>python3 <strong>-m<\/strong> http.server 80<\/pre>\n<p>Python <strong>FTP Server<\/strong>:<\/p>\n<pre>sudo apt-get install <strong>python3-pyftpdlib<\/strong>\r\nsudo python3 <strong>-m pyftpdlib<\/strong> -p 21<\/pre>\n<p>PIP is a package management system used to install and manage software packages written in Python.<\/p>\n<pre>sudo apt install <strong>python3-pip<\/strong>\r\n<strong>pip3<\/strong> install pyOpenSSL<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are discovering or studying Python, you may stay in the interpreter environment to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,6],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":11,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":5858,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions\/5858"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}