Getting started

This lecture explains how to install python, pip and ipython.

If you have the Nix package manager with Flakes, all dependencies are provided by:

nix develop github:johannesloetzsch/python-tutorial#example_getting_started_ipython

For Debian this should work:

sudo apt install python3 python3-pip ipython

Installation

For a reliable and secure setup, you should avoid downloading and installing programs manually.

Instead of following the instructions from https://www.python.org/downloads/, I highly recommend using the packet manager or app store of your operating system.

A good guide on how to install python on your system can be found at https://realpython.com/installing-python.

First test

You can run your first tiny python scripts directly from the command line using the -c argument of python:

python -c 'print("Hello world")'

python -c 'print(6*7)'

Tool recommendations

For bigger projects and professional development, several additional tools are recommended.

This tutorial is going to give an introduction into some of them.

venv

If you develop and integrate python projects, you will need different isolated versions of python and python packages for different projects. This can be achived by setting up virtual environments (venv) for each project:

python -m venv .venv
source .venv/bin/activate

pip

Soon we want to install additional python packages (libraries) from the Python Package Index (PyPI).

There exist serveral different package-management systems for python. The most widespread is pip.

For this tutorial we expect pip to be installed. In most cases the following command should work as described in the documentation:

python -m ensurepip

Otherwise this guide how to install pip should be helpfull.

After successful installation this command should work:

pip --help

IPython

For development of productive code, you will later write your python scripts into files.

Python allows another quick and easy way of testing ideas: you can open an interactive interpreter and run code directly there.

## Using the python-command without any arguments opens the interactive interpreter
python
>>> print("The interactive python shell is so usefull :)")
>>> exit()

A more enhanced interactive python shell is provided by the IPython package.

You can install it with the package manager of your operating system or use pip to install it:

 pip install ipython
ipython
>>> print("The interactive IPython shell is awesome :D")
>>> exit()

The IPython Tutorial explains how to efficiently use python interactively…