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.

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.

Knowing that your program was written in version 3, this is the command:

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’s output.

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):

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.

Interactive Mode – Instead of exiting when the program finishes, it will start an interactive session, which is very useful for debugging and prototyping.

python -i fileName.py

Using Python Modules [Link] for better productivity:

python -m SimpleHTTPServer 80

OR

python3 -m http.server 80

Python FTP Server:

sudo apt-get install python3-pyftpdlib
sudo python3 -m pyftpdlib -p 21

PIP is a package management system used to install and manage software packages written in Python.

sudo apt install python3-pip
pip3 install pyOpenSSL