---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
    jupytext_version: 1.11.5
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---
<div style="float: right;">
  <a href="../de/installation.html" style="margin-left: 10px;">🇩🇪 Deutsch</a>
  <a href="../en/installation.html">🇬🇧 English</a>
</div>

# 8. Installing Python, an IDE and packages
## Installing Python
To install Python on your local machine, you can either download the installer
from the official website or install conda, which is a version manager for
Python and other programming languages (like R).

### Using conda (recommended)
To download conda, please visit the [official conda website](https://conda.io/projects/conda/en/latest/user-guide/install/index.html).
You can choose to either install miniconda or Anaconda distribution (recommended). Miniconda is a barebone installation, while Anaconda distribution provides additional pre-installed features, which might be useful for you.
Follow the download instructions on the website and install the version of conda that you prefer. If you get stuck, you can watch a short tutorial in this ![YouTube video](https://youtu.be/WUeBzT43JyY?t=52) between 0:53 and 3:53, which will help you with the installation. If you still encounter problems, please don’t hesitate to send us an email.

````{margin}
```{note}
After conda is installed, you can, at any time, create a new programming environment for Python. Thus, if you have different projects that require different Python versions of packages, you can simply use conda to create a new environment. This is recommended to avoid conflicts between different packages and their versions.
```
````

#### Creating a New Python Environment

To work on the exercises in DaLi Topic 3, you can create a Python programming environment using conda.

To create a Python environment, open the "Environments" tab in the Anaconda Navigator. Once there, click the "Create" button at the bottom. You will then be asked whether you want to create a Python or R environment and which version you want to install. Simply choose Python and the desired version (e.g., 3.9).

```{margin}
### Using the official installer
To install Python using the official installer, please visit the [official Python website](https://www.python.org/downloads/) and install the version that you would like to use.
Please note that it is recommended to use the conda installer, because this will make it easier for you to manage different Python versions and packages later on.
```

## Installing packages
To use Python, you will sooner or later need packages. Python offers two main package managers: conda and pip. The installation of conda was described above, and pip is included automatically with every Python installation.

````{margin}
```{note}
Please note that these two package managers are not always compatible with each other. If you are using conda, it is recommended to install packages using conda. If you need to use both managers for the same Python environment, please make sure to first install as many packages as possible using conda and then install the rest using pip.
```
````

There are packages that can only be installed with either conda or pip, so it can be helpful to be able to use both. However, if you want to focus on just one at first, we recommend pip. Pip should cover about 95% of use cases.

To install packages with either package manager, you first need to open a terminal. In Anaconda Navigator, go to the "Environments" tab, click on the Python environment you just created, then click the green arrow directly to the right and select "Open Terminal" in the window that appears. This will open a terminal where you can type commands.

### 1) Using pip
To install a package using pip, you can simply open a terminal, type the following command and press enter:
```bash
pip install package_name
```
where `package_name` is the name of the package that you would like to install. For example, to install the package `numpy`, you can type
```bash
pip install numpy
```
### 2) Using conda
To install a package using conda, you can simply open a terminal and type
```bash
conda install package_name
```
where `package_name` is the name of the package that you would like to install. For example, to install the package `numpy`, you can type
```bash
conda install numpy
```

## Installing an IDE
An IDE (Integrated Development Environment) is a software that provides you with a graphical user interface to write and run your code. There are many different IDEs available for Python, but we recommend using either Jupyter Notebook or PyCharm. 
These can be installed manually or with the help of Anaconda Navigator, which comes with the installation of Anaconda distribution (not with miniconda though). To install them via Anaconda Navigator, just open said Navigator and as soon as it has started, you should see a list of programs that it supports. When you are at that screen, you can simply choose which IDE to install. 
If you are not using Anaconda Navigator, you can follow these steps:

### 1) Jupyter Notebook (Recommended for DaLi topic 3)
Jupyter Notebook is designed to work with interactive Jupyter Notebooks. It is organized in individual code blocks, which can be executed one at a time.
This is often used for teaching or demonstration purposes. E.g. this project is organized using Jupyter notebook-esque code blocks.
The downside of this IDE is that it is not very well suited for larger projects, as it is not designed to work with multiple files. For larger projects, we recommend using PyCharm.

The installation of Jupyter Notebook is included in the Anaconda distribution, so if you have installed Anaconda, you can simply open a terminal and type
```bash
jupyter notebook
```
to start the Jupyter Notebook server.

Alternatively, you can also start Jupyter Notebook in Anaconda Navigator under the "Home" tab by clicking "Launch."

### 2) PyCharm (Recommended for larger projects)
PyCharm is a professional IDE for large projects, similar to RStudio for R. It offers many features: multiple files, an integrated debugger, graphical management of conda environments, and more. However, its extensive functionality can be overwhelming for beginners.

````{margin}
```{note}
Alternatively, you can install PyCharm via the [official PyCharm website](https://www.jetbrains.com/pycharm/download/).
```
````

If you are using Anaconda Navigator, you can install PyCharm under the "Home" tab by clicking "Install" next to PyCharm Community or Professional. The Community Edition is free, while the Professional Edition is paid. If you have a university login, you can use the Professional Edition for free by linking your account with your university email at JetBrains, the developer of PyCharm.

For a tutorial, on how to use PyCharm, please visit the [official PyCharm tutorial](https://www.jetbrains.com/help/pycharm/quick-start-guide.html).