Category Archives: ubuntu 18.04

SIMPLE PROGRAMMING ENVIRONMENT WITH PYTHON-SPYDER

eJournal: uffmm.org, ISSN 2567-6458, 30.Dec 2018; extension 10.April 2019
Email: info@uffmm.org
Author: Gerd Doeben-Henisch
Email: gerd@doeben-henisch.de

CONTEXT

This post is part of the online book project for the AAI-paradigm. As mentioned in the text of the book the AAI paradigm will need for its practical usage appropriate software. Some preliminary (experimentally) programming is already underway. The programming language used for this programming is python. Here some bits of information how one can install a simple python environment to share these activities.

WINPYTHON OR ANACONDA WITH SPYDER
(Windows as well as Linux (ubuntu))

To work with the python programming language — here python 3 —  one needs some tools interacting with each other. For this different integrated development packages have been prepared.  In this uffmm-software project I am using the spyder development environment either as part of the winpython distribution or as part of the anaconda distribution.

WINPYTHON DISTRIBUTION

The winpython package can be found here. See also the picture below.

Website of winpython distribution
Website of winpython distribution

If one has downloaded the winpython distribution in some local folder then you will see the following files and folders (see picture below):

winpython distribution folder after installation
winpython distribution folder after installation

SPYDER INTEGRATED ENVIRONMENT

To use the integrated spyder environment one can also look to the spyder website directly (see picture below).

spyder working environment for python - website
spyder working environment for python – website

The spyder team recomments to download the spyder software as part of the bigger anaconda distribution with lots of additional options (see picture below).

spyder working environment embedded in the anaconda distribution
spyder working environment embedded in the anaconda distribution

Downloading the anaconda distribution needs much more time then the winpython distribution. But one gets a lot of stuff and the software is fairly good integrated into the windows 10 operating system. I personally recomment for the beginners not to beginn with the complex anaconda environment but to stay with the spyder integrated environment only. This can be done by activating with the windows-button the list of apps, looking to the anaconda icon, and there one can find the spyder icon (an idealized spyder web). One can click with the right mouse button on this icon and then select to ‘add to the task bar’. After this operation you can observe the spyder icon as attached to the task bar like in the picture below.

part of the task bar in windows with icons for spyder and a python environment
Part of the task bar in windows with icons for spyder (right border)  and a python environment (left from spyder)

If one activates the spyder icon a window opens showing some standard configuration of the integrated spyder development environment (see picture below).

spyder working environment with editor, console, and additional object informations
spyder working environment with editor, console, and additional object informations

The most important sub-windows are the window left from the editor and the window right-below from the console.  One can use the console to make small experiments with python commands and the editor to write larger source code.  In the header bar are many helpful icons for editing, running of programs, testing, and more.

LINUX (UBUNTU)

If one is working with linux (what I am usually are doing; I use the distribution ubuntu 18.04.1 LTS) then python is part of the system in version 2 as well in version 3 and spyder can be used too.

WINPYTHON CONSOLE

Besides the integrated development editor (IDE) spyder you can find even more programming tools. One very helpful tool is the WinPython Console (see icon within the red circle). You can attach this icon on your task bar too and then you can start the Winpython Console by clicking on it.

Figure 1: Directory path after starting the WinPython Console
Figure 1: Directory path after starting the WinPython Console

To apply this console to some python programm you have to navigate to that folder where you have the python program to be executed. If You do not know already the whole path then you have two options: (i) move the path upwards by using the command ‘cd ..’ (change directory one level upwards) or (ii) move the path downwards by using the command ‘cd DIR-NAME‘. If you are in a new folder you can use the command ‘dir‘ to list all the files and folders in the actual directory. Doing this You can reach the following folder with some python program files:

Figure 2: Folder with some python programs
Figure 2: Folder with some python programs

There is one example file pop0e.py which we can start (the whole program will be described later in detail).

Figure 3: Shows an example run with the program pop0e.py, some print outs as well as a diagram.
Figure 3: Shows an example run with the program pop0e.py, some print outs as well as a diagram.

For this last example with the Winpython Console the program can be edited by nearly any kind of a text editor. After the file has been saved with a .py ending one can use the console to start the program. In the last example (cf. figure 3) the important input was: ‘python pop0e.py‘ this states that the python interpreter shall take the program text of the file ‘pop0e.py’ and execute the program.

LEARNING ENVIRONMENT

For an overview of all posts in this block about programming with python 3 see HERE.