Test, ob Python schon vorhanden ist
Editor installieren
Installation von Thonny
Installation von PyICU
Linux
Die folgende Installationsanleitung bezieht sich auf Ubuntu 20.04, sollte aber auch mit allen anderen Ubuntu- und Debian-Versionen funktionieren. Für andere Linux-Distributionen, wie OpenSuse, RedHat, ..., ändert sich prinzipiell nur der Befehl für das Installieren von Paketen.
Zuerst öffnen wir ein Terminal, entweder aus der Programmliste, falls es dort schon vorhanden ist, oder mit der rechten Maustaste und dann aus dem angezeigten Menü den Punkt "Im Terminal öffnen":
Mit dem Befehl which python
und which python3
kann man erst einmal herausfinden, ob
aktuell überhaupt Python installiert ist. Dies dürfte nur in Ausnahmefällen zu einer leeren Ausgabe führen (keine Python-Installation vorhanden). Im
Allgemeinen wird man je nach vorhandener Konfiguration eine Ausgabe erhalten.
Mit dem Befehl python --version
oder python3 --version
wird die aktuell installierte Version angezeigt. In diesem Fall ist es Python 3.8.5,
welches für diesen Kurs völlig ausreichend wäre. Möchte man jedoch
die aktuelleste Version verwenden, so wird mit apt-cache search python | grep 3.9
kontrolliert, ob das Repository von Ubuntu
eine entsprechende Version beinhaltet:
Python 3.9 ist die aktuelle Variante, die man mit sudo apt install python3.9
installieren kann.
Da gleichzeitig noch die Version 3.8.5 installiert ist, zeigt python3
nach wie vor auf diese Variante. Zuerst löschen wir diesen
Link und erstellen dann einen neuen für python
mit ln -s /usr/bin/python3.9 /usr/local/bin/python3
wobei hier zur Kontrolle
in der folgenden Abbildung nach der Teileingabe von ln -s /usr/bin/python3
die TAB-Taste gedrückt wurde, um eine Kontrolle über die
installierten Versionen zu erhalten. Theoretisch kann man die Versionen 3.7 und 3.8 löschen, wenn man sich sicher ist, dass diese Varianten
nicht von anderen Programmen benötigt werden.
Nachdem der Link erfolgreich angelegt wurde, liefert python --version
die Ausgabe der neu installierten Version 3.9.0+.
Es kann durchaus sinnvoll sein, bei älteren Ubuntu-Distributionen nicht python
, sondern explizit python3
als
Link auf die neue Version zeigen zu lassen.
Für die Installation der aktuellsten Version gehe man nach https://www.python.org/. Für Linux gibt es aber keine speziellen Pakete; es sind die Quellen direkt selbst zu installieren. Für diesen Kurs ist das aber nicht erforderlich!
macOS
Für alle Varianten von macOS öffnet man ein Terminal (Finder->terminal->Enter) und gibt beispielsweise which python ein. Erfolgt keine Ausgabe, dann ist kein Python der Version 2 installiert. Die folgende Abbildung zeigt, welche Python-Varianten auf meinem System installiert sind und wie man sich die Versionen und die Verzeichnisse anzeigen lassen kann.
Die Version 2.7 ist hier der Standard für macOS (bis Catalina), sodass es sinnvoll ist, die neuere Version
zu installieren, was am besten mit dem Paketmanager homebrew
erfolgt. Haben Sie diesen schon installiert, können
Sie den folgenden Schritt überspringen. Anderenfalls öffnen Sie wieder
ein Terminal oder gehen in ein bereits geöffnetes Fenster und geben folgende Zeile an, die Sie auch mit MArkieren und dann Kopieren und
Einfügen erstellen können:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Nachdem dies erfolgreich war, lässt sich mit dem Programm brew
jedes nicht Apple-eigene Paket installieren. In diesem Fall
führen wir folgens aus:
brew install python3
Danach sollte ein Python der Version 3 installiert sein:
# Hinweis iMac: voss$ `which python3` --version Python 3.10.10
Bei macOS Ventura gibt es kein Python2 mehr, sodass auch schon der Aufruf von python die aktuelle Version benutzt.
Installation eines Editors
Editoren, die eine Softwareentwicklung mit Python unterstützen, gibt es mittlerweile reichlich: Vollständige Liste. Der Editor wird für die Bearbeitung des sogenannten Quellcodes (Programm) benötigt, welches dem Interpreter oder Compiler zur Bearbeitung übergeben wird.
Für diesem Kurs empfehle ich insbesondere für Anfänger den einfachen Editor Idle. Sie können aber ohne weiteres mit einem anderen Editor arbeiten, wenn der Ihnen angenehmer erscheint.
PyCharm
Platform: Windows, Linux and macOs
It is one of the best and only full-featured Python-specific IDE which is developed by JetBrains who are also the creator of IntelliJ IDEA, WebStorm and PhpStorm. PyCharm offers innumerable cutting-edge features and gives smart assistance to the developers. This IDE helps the developers to write neat and maintainable codes which enhances their productivity. Additionally, it is available in both paid and free versions.
Features:
- Intelligent code editor and smart code navigation
- Integrated with debugging, testing, deployments, tools of the database and other features.
- Supports JavaScript, HTML, CSS, Angular JS and other languages
- Error detection and quick fixing
- Powerful integration with IPython notebook and scientific stack
- Customizable interface
- Rich Community
Cons:
- Slow to load
- Default settings may need tweaking
- The initial installation might be difficult
Spyder
Platform: Windows, Linux and macOS
It is an open-source IDE that is famous for Python development. Spyder is a very extensible IDE that was mainly developed for scientists and engineers for providing a scientific environment. This IDE also integrates well with popular libraries related to data science such as NumPy, SciPy and Matplotlib. Among countless features, one of the unique features it possesses is “variable explorer”. This feature shows data to any developer in a table-based layout within the IDE itself. If you are into data science work and uses Python then there is a higher chance of you to like this IDE.
Features:
- Offers an advanced level of editing, debugging and data exploration
- Good plugin system and API
- Syntax highlighting and auto code completion
- Powerful integrations with iPython console
- Can explore and edit variables from GUI itself
Cons:
- Experienced Python developers might find this IDE too basic to work with
- Performance gets reduced while several plugins are invoked at the same time
Thonny
Platform: Windows, Linux and macOS
Thonny is one of the most recent IDE which joined the Python’s IDE family. It is one of the best IDE for beginners having no or little experience of Python and is maintained by the Institute of Computer Science at the University of Tartu in Estonia. When it comes to its features, Thonny is very basic and simple and, you can find all the installation instructions on its website.
Features:
- Simple debugger
- A good representation of function calls
- Highlighting errors and auto code completion
- No-hassle variables
- Beginner friendly system shell
- Simple and clean GUI
- Explains scope by spots highlighting
Cons:
- Lack of support for templates
- Interface is limited to text editing
Installation von Thonny ist einfach: Gehen Sie zu https://thonny.org und wählen gleich oben rechts die für Ihr System korrekte Version.
Wing Python IDE
Platform: Windows, Linux and Mac
This IDE is designed specifically for development in Python and comes in three different editions i.e. 101, Personal and Pro. Among all, the 101 version is the simplest version having a minimalist debugger, basic editor and simple search. While the Pro version includes all the advanced features such as extensive code inspection, remote development, unit testing, refactoring and others.
Features:
- Intelligent editor, auto-completion, inline error detection and code quality analysis
- Auto-editing, refactoring, code folding, multi-selection, customizable code snippets
- Powerful debugger
- Easy code navigation with goto-definition, find uses, powerful multi-file search and others
- Integrated unit testing
- Remote development
Cons:
- It does not support the dark theme
- Expensive commercial version
Eclipse+PyDev
Platform: Windows, Linux and macOS
Eclipse is one of the most used IDE by the developers. It provides a rich set of extensions and add-ons. One such extension is PyDev which is commonly used for Python-related development with Eclipse. The combination of Eclipse and PyDev allows a developer to code more efficiently by providing several features. Moreover, installing PyDev in Eclipse is also very easy.
Features:
- If Eclipse is installed, then you can easily and quickly add PyDev.
- Debugger
- Interactive console
- Refactoring
- Token browser
- Strong syntax highlighting and code folding
- Code completion and analysis
Cons:
- Sometimes PyDev becomes unstable
- If you’re a beginner then using Eclipse will be difficult
- PyDev performance decreases with multiple plugins
Sublime Text
Platform: Windows, Linux, and macOS
It is another popular code editor which supports all the platform. Sublime text is developed on C++ and Python, and includes Python API. This code editor has built-in support for Python code editing and consists of hundreds of extensions (packages) which can extend its functionality.
Features:
- Go To Anything for quick navigation to symbols, lines or words
- Go To Definition for automatically generating a project-wide index of every class, method and function.
- Syntax highlighting
- Auto code completion
- Command palette
- Fast, small and well-supported
- Highly customizable
- Allows split editing and instant project switch
- Powerful API
Cons:
- Weak Git plugin
- Installation can be tricky
- No direct support for executing or debugging code within the editor
Atom
Platform: Windows, Linux and macOS
Atom is a code editor and is built with the Electron framework which is used to built desktop applications using JavaScript, HTML and CSS. It is a perfect editor having “cheats” for your every problem and because of this, the editor is also referred to as a “hackable” text editor of the 21st century. Atom is free and is based on atom shells which are a framework helping developers to achieve cross-platform functionality. Numerous plugins are available for Atom making it more customizable and extending its features. Moreover, it can also be used as an IDE.
Features:
- Supports cross-platform
- Built-in package manager
- Smart and flexible auto code completion
- Plugins support
- Multiple panes
- Simple to use
- Support from GitHub crew
- Downloads and loads fast
Cons:
- Tabs are clumsy and sometimes, reduces the performance
- No built-in debugger but is provided as an add-on by the community
Vim
Platform: Windows, Linux, macOS
Vim is a popular editor which can be used for creating or modifying any type of text. It is highly configurable and a very stable text editor. With each new release, it gets better and better, improving its performance quality.
Features:
- Persistent
- Supports multiple platforms
- Highly configurable
- Extensive plugins
- Supports multiple programming languages
- Provides normal and editing mode to the users
- You can save and reuse the strings in VIM
- Supports non-programming applications
Cons:
- Difficult to learn at the beginning
- Just a text editor
- Poor support for external tooling
IDLE
Platform: Windows, Linux, macOS
IDLE is Python’s Integrated Development and Learning Environment.
Features:
- coded in 100% pure Python, using the tkinter GUI toolkit
- cross-platform: works mostly the same on Windows, Unix, and macOS
- Python shell window (interactive interpreter) with colorizing of code input, output, and error messages
- multi-window text editor with multiple undo, Python colorizing, smart indent, call tips, auto completion, and other features
- search within any window, replace within editor windows, and search through multiple files (grep)
- debugger with persistent breakpoints, stepping, and viewing of global and local namespaces
- configuration, browsers, and other dialogs
Cons:
- Not useful for big projects
Installation von idle3 unter Ubuntu/Debian
Nach Öffnen eines Terminals kann man zuerst kontrollieren, ob eine entsprechende IDLE-VErsion verfügbar ist:
# Hinweis voss@h2710458:~$ apt-cache search idle3 idle3 - IDE for Python using Tkinter (transitional package) idle3-tools - change the idle3 timer of recent Western Digital Hard Disk Drives
Sollte hier keine Ausgabe erscheinen, so hat man ein relativ altes Linux-System und muss dann auf IDLE2 ausweichen. Hier installieren wir "idle":
# Hinweis voss@h2710458:~$ sudo apt install idle3 [sudo] Passwort für voss: Paketlisten werden gelesen... Fertig Abhängigkeitsbaum wird aufgebaut. Statusinformationen werden eingelesen.... Fertig Die folgenden zusätzlichen Pakete werden installiert: idle idle-python3.6 Die folgenden NEUEN Pakete werden installiert: idle idle-python3.6 idle3 0 aktualisiert, 3 neu installiert, 0 zu entfernen und 0 nicht aktualisiert. Es müssen 265 kB an Archiven heruntergeladen werden. Nach dieser Operation werden 1.316 kB Plattenplatz zusätzlich benutzt. Möchten Sie fortfahren? [J/n]
Danach kann man entweder direkt über Eingabe von "idle3" im Terminal oder über "Anwendungen->Programmierung->IDLE" den Editor starten
Installation von idle3 unter macOS
Hat man eine erfolgreiche Python-Installation (https://www.python.org/downloads/), dann ist auch automatisch ein aktuelles IDLE installiert, welches allerdings nicht im Ordner Programme erscheint. Über den Finder kann man es lokalisieren und dann über Ablage es entweder in der Seitenleiste vom Finder oder im Dock permanent machen.
Installation von idle3 unter Windows
Ebenso wie bei macOS kommt IDLE mit einer erfolgreichen Installation von Python:
Gestartet werden kann IDLE über Windows->Python:
Der Startbutton kann auch zur Vereinfachung auf den Desktop gezogen werden, um dort permanent angezeigt zu werden.
Installing PyICU
International Components for Unicode (ICU) is an enterprise library for Unicode support. Being both very enterprise and Unicode orientated, it is stupidly complex. I hope you’ll never need it, but if you do, luckily there’s a Python library (PyICU) for that. But as it just interfaces with the ICU C library, PyICU can be tricky to install.
macOS
# Hinweis # You should have an existing brew. If not run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # First remove existing packages brew uninstall --ignore-dependencies icu4c pip uninstall pyicu # remove old packages in the Cache rm -fr ~/Library/Caches/pip # install libicu (keg-only) brew install pkg-config icu4c # let setup.py discover keg-only icu4c via pkg-config export PATH="/usr/local/opt/icu4c/bin:/usr/local/opt/icu4c/sbin:$PATH" export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/icu4c/lib/pkgconfig" # EITHER - when using a gcc-built CPython (e.g. from Homebrew) export CC="$(which gcc)" CXX="$(which g++)" # avoid wheels from previous runs or PyPI pip install --no-binary=:pyicu: pyicu brew link pyicu
Installing PyICU on Windows
From lfd.uci.edu
get the latest python wheel version, eg
PyICU‑2.9‑cp311‑cp311‑win_amd64.whl
for Windows 64Bit and
Python 3.11. Then install this package with pip or your editor.
Now try the following example, where z should be the last in the sorted list:
import icu z = ["z","Ä","ä","ß"]# without unicode print(sorted(z)) collator = icu.Collator.createInstance(icu.Locale('de_DE.UTF-8')) print(sorted(z, key=collator.getSortKey))
Nächste Einheit: 01 Variablen