22 C
Guru Unix /Linux and GNU supporter

Linux Python 101

Python is one of the most popular programming languages of all, no doubt. In the case of any Linux distro, Python is completely irremovable as it performs lots of important tasks from the core to any software. Today, let’s take a look at some of the basic Python commands and tricks.

Python versions

At first, you have to know that there are 2 major versions of Python – Python 2.x and 3.x. Python 2.x is the older release. It’s still quite good, but not actively maintained. That makes Python 3.x the obvious choice for the long run. There are some syntax changes in Python 3.x, so for compatibility, both are required to be present in your system.

For installing Python in your Linux system, run the following command(s) according to your distro.

  • Ubuntu
# Python 2.x
sudo apt install python

# Python 3.x
sudo apt install python3
  • Debian
- Advertisement -
# Python 2.x
sudo apt-get install python

# Python 3.x
sudo apt install python3
  • OpenSUSE
sudo zypper install --type pattern devel_C_C++ devel_python
sudo zypper in libopenssl-devel libffi48-devel bluez-devel sqlite2-devel tk-devel valgrind-devel libexpat-devel sqlite3-devel readline-devel readline-devel-32bit libbz2-devel libexpat-devel libbz2-devel readline-devel sqlite3-devel

cd /usr/src
wget -c https://www.python.org/ftp/python/3.7.0/Python-3.7.0b5.tar.xz
tar xvf Python-3.5.2.tar

CXX="/usr/bin/g++" \
./configure --prefix=/usr \
--enable-shared \
--with-system-expat \

make test
make install
  • Fedora

Python comes pre-installed on Fedora. Make sure to grab the latest version by upgrading all your software package to the latest version.

sudo yum -y update
  • Arch Linux

Download Python 3.x and/or Python 2.x for Arch Linux.

pacman -U /root/Download/python2-2.7.15-1-x86_64.pkg.tar.xz

pacman -U /root/Download/python-3.6.5-3-x86_64.pkg.tar.xz
  • Other distros

For other distros, you have to build it from source. Download the latest source of Python. Extract the compressed file into a suitable folder.

Then, run the commands:

cd Python-3.6.5

make test
sudo make install

Python commands

Here are some of the basic commands of Python.

This command shows the installation path of Python binary.

which python
which python3


Check out installed Python version –

python -V
python3 -V

Exit Python shell –

>>> quit()

It’s always a good idea to make sure to use the latest version, right? You can symlink the command “python” with “python3”. Run the following commands –

sudo rm /usr/bin/python
cd /usr/bin
sudo ln -s python3.6 python

For developers, there’s an official Python IDE (IDLE). Let’s install and fire it up.

# Debian and derivatives
aptitude search idle

# CentOS and Fedora (older than 23) and derivatives
yum search idle

# Fedora (23 and up)
dnf search idle

Now, install the favorite version of yours like the following command:

sudo aptitude install idle-python3.6

Of course, the IDE looks more like the shell, but it’s better to keep in mind that you have more power on IDLE than the shell.

There are also other Python IDEs and editors like Thonny, PyCharm, Visual Studio Code etc. There are also other IDEs worth checking out. Take a look at the best IDEs of 2018.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article