Python in Linux

[ debian ]

https://www.debian.org/
Debian. The universal operating system.

INTRODUCTION

Good news: Python is probably installed in your system!


# Open a Terminal window.

$ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python'
>>> quit()     # back to the shell
$

$ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python3'
>>> quit()
$

Three systems for managing Python packages can be used in Linux:
(1) apt (Debian) or rpm (Red Hat),
(2) pip,
(3) conda (Anaconda).


# Info about your system.
# uname - get name and information about current kernel

$ uname --all     # on Dell Latitude 5501 64-bit
Linux debian 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux

$ uname --all     # on Toshiba Tecra A7 32-bit
Linux debian 4.19.0-11-686-pae #1 SMP Debian 4.19.146-1 (2020-09-17) i686 GNU/Linux

$ env     # if no COMMAND, print the resulting environment
# ... selected variables ...
SHELL=/bin/bash
LANGUAGE=pl_PL.UTF-8
LOGNAME=andrzej
HOME=/home/andrzej
LANG=pl_PL.UTF-8
PYTHONPATH=/home/andrzej/python_modules:...   # 
USER=andrzej
LC_ALL=pl_PL.UTF-8
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

$ cd        # back to the home directiory

$ less .bashrc     # setting PYTHONPATH
# ... selected lines ...
if [ -n "${PYTHONPATH}" ] ; then
    PYTHONPATH="${PYTHONPATH}:$HOME/python_modules"
else
    PYTHONPATH="$HOME/python_modules"
fi
export PYTHONPATH
export LC_ALL="pl_PL.UTF-8"
export LANGUAGE="pl_PL.UTF-8"

EDITORS

Console editors: nano, mcedit (with Midnight Commander).

Editors with GUI: gedit (GNOME), kate (KDE).

DESKTOP ENVIRONMENTS

https://www.tecmint.com/best-linux-desktop-environments/

A Desktop Environment is a collection of different user and system programs running on top of an operating system, and share a common GUI (Graphical User Interface), also known as a graphical shell.

Parts of a desktop environment:
a window manager,
a file manager,
desktop notifications,
launchers,
a display manager,
a session manager,
configuration tools.

Most popular Linux desktop environments:
GNOME 3 Desktop
KDE Plasma 5
Cinnamon Desktop
MATE Desktop
Xfce Desktop (lightweight)
LXQt Desktop (lightweight)

DEBIAN APT

APT is Advanced Package Tool, the main command-line package manager for Debian and its derivatives.

'Synaptic' is a graphical interface to the Debian package management system.
[run /usr/bin/synaptic-pkexec as 'root']

Command-line tools dedicated to package management in Debian: dselect, aptitude, apt-get, apt.

SCRIPTS IN LINUX

Create a file 'hello.py'. Run the script.


#!/usr/bin/env python
# coding: utf-8
#
# Your first program in Python (2 or 3).
# '#!' is called 'hash bang', it is used by the Linux shell.
# Usage:
# python hello.py [number]
# ./hello.py [number]

import sys
import math

if len(sys.argv) == 1:
    r = 1.0
else:
    r = float(sys.argv[1])

s = math.sin(r)
print("Hello, sin({}) = {}".format(r, s))

#input("Press any key ...")   # on Windows

$ python hello.py
Hello, sin(1.0) = 0.841470984808
$ python hello.py 2
Hello, sin(2.0) = 0.909297426826
$ chmod a+x hello.py     # add ('+') the 'x' (execute) mode bit to all users ('a')
$ ./hello.py
Hello, sin(1.0) = 0.841470984808