Run Python Scripts on Linux

This section provides a tutorial example to verify Python environment supported on Linux computers and run a simple Python interactive scripting session.

Linux computers support Python out-of-the-box. You don't have to do any installation to run Python scripts. Here is what I tried on my macOS computer.

1. Start a Terminal window and try to run Python scripts interactively as shown below:

herong$ python --version
Python 3.6.8

herong$ python
Python 3.6.8 (default, Aug 24 2020, 17:57:11)
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> print "Hello world!\n"
Hello world!

>>> exit()

Note that you need to call the "exit()" function to terminate the Python interactive session.

2. If you just want to run one line of Python code, you can specify it in the command option "-c" as shown below:

herong$ python -c 'print "Hello world!\n"'

Hello world!

3. If you have a Python script file, you can run it in non-interactive mode as command argument as shown below:

herong$ python

Hello world!

Table of Contents

 About This Book

 Running Python Code Online

 Python on macOS Computers

Python on Linux Computers

Run Python Scripts on Linux

 Install Python 2 Environment on CentOS

 Built-in Data Types

 Variables, Operations and Expressions

 Statements - Execution Units

 Function Statement and Function Call

 Iterators, Generators and List Comprehensions

 Classes and Instances

 Modules and Module Files

 Packages and Package Directories

 "sys" and "os" Modules

 "pathlib" - Object-Oriented Filesystem Paths

 "pip" - Package Installer for Python - Python Libraries for Science

 pandas - Data Analysis and Manipulation

 Anaconda - Python Environment Manager

 Jupyter Notebook and JupyterLab


 Full Version in PDF/EPUB