Ex Data, Scientia

Home Contact

How to get started with Python

Finding the right entry-way into programming Python is not as straghtforward as one might think. There are a number of tricks that make working with Python really convenient, though.

When I started working on my Master thesis concerning automatic image classification using Deep-Learning techniques, I realized I needed to do it in Python, since this was the language commonly used for such tasks. However, with my background as a student of marine ecology, I was only familiar with the R programming language and its IDE, RStudio.

Therefore, not knowing how best to set up my Python "working desk", I started by simply downloading the Python program (the old-fashioned way, by clicking on a button on the Python homepage, that is). I then downloaded an editor program that was very awkward to work with (its name escapes me having abandoned it long ago).

It was only later that I found out how to really install Python in a reasonable way, and would like to share this knowledge here with you, so that you will hopefully have a smoother start than I had.

The first thing of importance is that there exists a very convenient "wrapper program" called Anaconda. Anaconda is the ideal entry-point to Python, the "starter kit", if you will. It will help you install Python, so before proceeding to the Python website yourself, you should better download Anaconda, and let it do the job for you.

Anaconda can be downloaded from the following website: www.anaconda.com/products/individual. Once downloaded, you have a good base for setting up your Python "working desk".

One further important fact that I learned along the way is that one usually works in so-called environments when using Python. That is, you actually create several parallel installations of Python and associated packages. This is due to the fact that you may require some functions of an older version of a certain package, but also other functions from a newer version for a different script or application. Or you would liketo install a package whose functionality depends on a version of another package that is different from the one you have already installed and like to work with. Obviously, you cannot install two package versions into the one "space". This is where the convenience of Anaconda comes into play: With a simple line of code (which is entered into the command line), you can create an environment. And another one, and another one, ...:

  conda create --name my_env

If you simply want to duplicate an environment, maybe because you want to install a package that could overwrite an existing version of another package with the version that it depends on, you can clone your existing environment:

  conda create --clone my_env --name my_env_2

After having created an environment, you have to activate it before you can start working in it. This simply means that you enter the "door" of this environment, while before you were in the so-called base environment. Once you have activated the environment, the prompt on the command line will change from "base" to the name of the environment.

Now you can use Anaconda to install the packages you need. Note that Anaconda already pre-installs a number of packages that are of general usefulness. If you require a specific version of a package to be installed, you can simply add the suffix "=xxxx":

  conda install numpy=1.15.4

Some packages can not be installed via Anaconda. These packages have to be installed using the command "pip"e;, which stands for "pip installs Python"! The difference between the installation via Anaconda and the installation via pip is that the former will always advise you about compatibility issues and demand an input to proceed, while the latter will simply install the packages and its dependencies, no matter if this means that an existing package will be over-written. Not knowing of the existence of Anaconda, I initially tried to install all my packages with pip, and soon ran into trouble.

The − in my opinion − ideal editor to work with Python is Spyder, a complete Integrated Developer environment (IDE) close to RStudio in look and feel. Spyder highlights the different parts of your code, points out synthax errors and redundant bits of code, a detailed overview of your variables, and a history traceback of your console input. It really makes working with Python a convenient experience.

Thus, three key messages have arisen: Use Anaconda to install Python, work in environments, ans use Spyder to write your Python scripts. Whe following these recommendations, you are fully geared to start your programming work!