{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Unit 1 - Setup / Anaconda / Jupyter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Installing Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**We use Python 3.** (Current Version 3.7.0)\n", "\n", "Plain Python: https://www.python.org/downloads/\n", "\n", "For this course: https://www.anaconda.com/download/\n", "\n", "Why _Anaconda_? \n", "Anaconda simplifies Python installation, extension and updating. It includes:\n", "* the python interpreter\n", "* lots of useful packages\n", "* conda package manager\n", "* _Spyder_ IDE\n", "* _Jupyter_ notebooks\n", "* extensive learning resources\n", "\n", "Alternatively: https://conda.io/miniconda.html\n", "* the python interpreter\n", "* conda package manager $\\rightarrow$ users can install only the packages they need" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Environment Variables (if not set automatically)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To access the python interpreter via the command lines, its location has to be added to the environment variable _path_. Sometimes this happens automatically, sometimes not. It can be forced by selecting the checkbox \"Add Anaconda to the system PATH environment variable\" during installation of Anaconda.\n", "\n", "Check if it worked:\n", "* Open a command line window (in the start menu, enter \"cmd\" and press \"Enter\")\n", "* Enter \"python\"\n", "* If \"Python 3.X.X ...\" is displayed, you're good to go!\n", " * If it says \"Python 2.X.X ...\", there is a previous installation of python 2 on the computer, do not use that! On Linux, you usually have to enter \"python3\".\n", "* Otherwise, follow these instructions to set the environment variable manually:\n", "\n", " * Find python's installation folder (default: C:\\Users\\\"Your Username\"\\Anaconda3 or C:\\ProgramData\\Anaconda3), i.e. the folder in which the \"python.exe\" is located\n", " * Right click on \"This PC\" (\"Computer\"/\"Dieser PC\")\n", " * On windows 10, you should be able to just begin typing \"variable\", select \"Edit enviroment variables\" and jump over the next 3 steps\n", " * Select \"System Properties\" (\"Eigenschaften\")\n", " * On the top left, select \"Advanced system settings\" (\"Erweiterte Systemeinstellungen\")\n", " * On the bottom right, select \"Environment variables\" (\"Umgebungsvariablen\")\n", " * Select \"Path\" (in the top if you only want to set it for the current user, in the bottom if it should work for all users on the computer)\n", " * Click \"Edit\" (\"Bearbeiten\")\n", " * Add the installation folder's path to the list of paths and close all windows with \"OK\"\n", " * Check again if it worked!\n", " * (On windows 10, you should be able to just begin typing \"variable\" and select \"Edit enviroment variables)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 2. Writing a simple program" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2.1 Using a text editor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As for most programming languages, any text editor can be used to write python code. Operating systems usually provide a rudimentary text editor (notepad.exe in Windows), but there are far better options available:\n", "* Sublime Text 3 (https://www.sublimetext.com/3):\n", " * Proprietary license, but unlimited testing for non-commercial use, i.e. free for you ;)\n", " * Fast editing with keyboard shortcuts and multiple cursors\n", " * Lots of plugins (also python-specific)\n", "* Notepad++ (https://notepad-plus-plus.org/download)\n", " * Freeware" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Important** \n", "Whatever editor or IDE you are using, set it so that instead of tabs, 4 spaces are used to comply with the course's requirements! Usually, you can also set a ruler to remind you of the 72 character limit per line" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Now to the program** \n", "1. In the editor of your choice, create a new file and name it hello_python.py\n", "2. Write the following into the file: print(\"Hello, Python!\")\n", "3. Save the file\n", "4. Use a console (cmd or powershell for windows) and navigate to the folder of the previously created file\n", "5. type python hello_python.py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2.2 Using the Spyder IDE" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Startup Spyder\n", "2. Write print(\"Hello, Python!\") into a new file\n", "3. Click the little green \"Run\"-button at the top" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3. Jupyter Notebooks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Jupyter Notebooks allow the creation of documents including python code inside a browser. We will use them to present the tutor sessions. They make it easy to create little scripts and try things out. \n", "The Notebook server can be launched by searching for \"Jupyer Notebook\" in the start menu (or typing \"jupyter notebook\" in a command line). If no browser window opens automatically, copy the link displayed in the command line window and load the page manually.\n", "\n", "## Basic usage\n", "* Code and text can be written in cells.\n", "* Cells can be executed individually and out of sequence.\n", "* Cells know what happened in other cells (but only if those have already been run)\n", "* Cells are run by pressing \"Shift\"+\"Enter\" or \"Ctrl\"+\"Enter\"\n", "* Markdown and Latex can be used in text cells\n", "\n", "Try executing the following example!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Hi!\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }