# Python Installation & Packages

### Step 1: Download and Install Python via website

1. <mark style="color:orange;">**Visit the Python website:**</mark>&#x20;

   Go to the[ Python website ](https://www.python.org/)in your browser.&#x20;
2. <mark style="color:orange;">**Download Python:**</mark>

   Click on the "Downloads" tab, and you'll see a button for the latest version of Python. Click on it to start the download.

{% hint style="warning" %}
Be careful of downloading the Python version that is compliant with your system (Windows, MacOS, or Linux)
{% endhint %}

3. <mark style="color:orange;">**Run the Installer:**</mark>\
   Once the download is complete, open the installer from you Downloads directory. Make sure to check the box that says "Add Python to PATH" during the installation. This makes it easier to run Python from the command line.
4. <mark style="color:orange;">**Verify Installation:**</mark>

   Open a command prompt (on Windows or on macOS using [Git Bash ](https://disc4all-qupath.gitbook.io/qupath-project/non-expert-docs/git-bash-installation-1)or Linux) and type:&#x20;

   ```bash
   python --version
   ```

   &#x20; This should display the installed Python version, confirming a successful installation.

## Step 1A: Dowloading Python via Git Bash prompt

1. <mark style="color:orange;">**Open a Git Bash Terminal or Command Prompt:**</mark>

   You can do that opening the search bar and type in "**Git Bash**" and select the Git Bash application.
2. <mark style="color:orange;">**Navigate to a Directory:**</mark>

   In this case, navigate to the ProjectFolder using the path:&#x20;

```
cd Path/to/ProjectFolder
```

3. <mark style="color:orange;">**Download Python Installer:**</mark>&#x20;

   Use the ***`curl`*** command to download the Python installer. You can get the link for the latest version from the [Python website ](https://www.python.org/) page.&#x20;

   * Go to the **Dowloads** section, search for the newest version compatible with your computer system,  click on it and on the *address ba*r of the webpage you can copy the **url** of the version using **Ctrl + C**. Replace ***`<version>`*** with the desired version using ***Shift + Insert*** in the Git Bash terminal when typing this command:&#x20;

{% code overflow="wrap" %}

```
curl -O https://www.python.org/ftp/python/<version>/python-<version>-amd64.exe
```

{% endcode %}

For example, to downlad *Python 3.9.7:*

```
curl -O https://www.python.org/ftp/python/3.9.7/python-3.9.7-amd64.exe
```

4. <mark style="color:orange;">**Run Python Installer:**</mark>

   Execute the downloaded Python installer using the **`start`**&#x63;ommand.

```
start python-<version>-amd64.exe
start python-3.9.7-amd64.exe #as in the previous example
```

5. **Python Installer Setup:**
   * The Python installer will open. Make sure to check the box that says "Add Python to PATH" during installation.&#x20;
   * Click "Install Now" to proceed with the default settings.
6. **Wait for Installation and Verify it:**
   * Open a new Git Bash terminal and check if Python is installed by typing:

```
python --version
```

7. Done! Now you can come back to the original Git Bash prompt to continue with the Data Science Packages.&#x20;

### Step 2: Install Data Science Packages

Now that you have Python installed, you can use the package manager `pip` to install the data science packages you need.&#x20;

1. <mark style="color:orange;">**Open a Terminal or Command Prompt:**</mark>&#x20;

   Open a terminal or command prompt, depending on your system. Use [Git Bash](https://disc4all-qupath.gitbook.io/qupath-project/non-expert-docs/git-bash-installation-1) if on Windows/MacOS directly from the Start Menu.&#x20;
2. <mark style="color:orange;">**Install pandas, numpy, seaborn, and matplotlib:**</mark>

   Type the following command and press Enter:

   ```bash
   pip install pandas numpy seaborn matplotlib scipy openpyxl
   ```

   This command installs the required packages:&#x20;

   * <mark style="color:orange;">pandas</mark>: Data manipulation and analysis library.
   * <mark style="color:orange;">numpy</mark>: Numerical computing library.
   * <mark style="color:orange;">seaborn:</mark> Statistical data visualization library based on matplotlib.
   * <mark style="color:orange;">matplotlib</mark>: Plotting library for creating static, animated, and interactive visualizations.&#x20;
   * <mark style="color:orange;">scipy:</mark> Modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing
   * <mark style="color:orange;">openpyxl:</mark> Library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files
3. <mark style="color:orange;">**Verify Installation:**</mark>&#x20;

   You can verify the installation by opening another Git Bash terminal and open there a  Python shell (type ***python*** in your terminal) and trying to import each library:                                              &#x20;

   ```python
   import pandas
   import numpy
   import seaborn
   import matplotlib
   ```

   If there are no errors, the packages are successfully installed.

{% hint style="success" %}
Congratulations! You've now installed Python and some essential data science libraries. You're ready to start the analysis and follow the tutorial[ here](https://disc4all-qupath.gitbook.io/qupath-project/result-analysis-docs/processing-package-tutorial#step-by-step-python-tutorial).&#x20;
{% endhint %}

> **License**:&#x20;
>
> Van Rossum, G., & Drake, F. L. (2009). *Python 3 Reference Manual*. Scotts Valley, CA: CreateSpace.
>
> [Data structures for statistical computing in python](https://conference.scipy.org/proceedings/scipy2010/pdfs/mckinney.pdf), McKinney, Proceedings of the 9th Python in Science Conference, Volume 445, 2010.
>
> Harris, C.R., Millman, K.J., van der Walt, S.J. et al. *Array programming with NumPy*. Nature 585, 357–362 (2020). DOI: [10.1038/s41586-020-2649-2](https://doi.org/10.1038/s41586-020-2649-2).
>
> Waskom, M. L., (2021). seaborn: statistical data visualization. Journal of Open Source Software, 6(60), 3021, <https://doi.org/10.21105/joss.03021>.
>
> J. D. Hunter, "Matplotlib: A 2D Graphics Environment", Computing in Science & Engineering, vol. 9, no. 3, pp
