Python Environment Setup

This lesson will teach you how to setup your own computer with Python.

Introduction



    In terms of computers, an environment is just the state of the computer based on the software, hardware and settings that it has.

    Before you can do machine learning from your own computer, we need to make sure the environment is ready.

    This means that your computers hardware, software and settings must be compatible and configured correctly.

    This lesson will contain instructions for setting up Python for Windows, Linux and Mac.

Hardware Requirements



    Machine learning and deep learning can be intensive on a computer.

    You need to make sure that your computer has sufficient requirements.

    Windows/Linux
    1. Central Processing Unit (CPU) - Intel Core i5 6th Generation processor or higher. An AMD equivalent processor will also work.
    2. RAM - 8 GB minimum, 16 GB or higher is recommended.
    3. (Optional) Graphics Processing Unit (GPU) - NVIDIA GeForce GTX 960 or higher. AMD GPUS are not recommended.

Software



    There are many different software, tools and packages that are used for machine learning with python.

    We will be using a few of the most common ones:
    1. Python Distribution - The python install comes with many of the essential tools we need such as IDLE, Pip and the Python language itself of course.
    2. Programs and Libraries - Both the 'Intro to Python for Machine Learning' course and the 'Machine Learning and AI with Python' course use programs with additional libraries. You will be shown how to install each one.

Installing Python



    Before you can start machine learning, you will need to install Python on your machine.

    There are two ways to do this:
    1. Plain Download - This will be used for the 'Intro to Python for Machine Learning and AI' course (this course).
    2. Installing with Anaconda - This will be used for the 'Machine Learning and AI with Python' course (next course).

    Since we will be using the default Python download for the first course, you should only do this for now.

    There is a separate guide for installing with Anaconda but this will only be used in the second course.

    Start by dowloading Python here. Choose the newest release version (or atleast version 3.8.1 or newer).

    This will take you to the dowloads page. You will see the downloads in the Files section at the bottom of the page. Choose the installer for your operating system.

    Windows 64-bit: Windows x86-64 executable installer

    Windows 32-bit: Windows x86 executable installer

    macOS 64-bit: macOS 64-bit installer

    Linux: Gzipped source tarball. These are source files, not an installer. You will need to install these source files manually.




    Open the installer and follow the installation instructions.

    Select the box for Add Python X.X to PATH which tells the computer where to find Python when we search in the command line.

    Click Install Now. This is the default installation option that includes Python, IDLE (Integrated Development Environement), pip and the official documentation.

    Do not use 'customize installation' unless you have advanced knowledge.


    Once the install has finished, click close to close the installer.

Command Line



    To check that Python has installed correctly and for things we will do later, we need the command line.

    The command line is a text interface for your computer that takes in commands for the operating system to run.

    It is also referred to as the terminal, prompt, shell, console and more.

    Each operating system has a different command line:
    1. Windows - You can open this by clicking Start and in the Search or Run line, type cmd (short for command), and press Enter.

      Read more about How to use the Windows command line.
    2. Mac OS - You can open this by going to your Applications folder, then the Utilities folder and clicking on Terminal. Alternatively you can just type Terminal in the Spotlight search.

      Read more about How to use the Mac command line.
    3. Linux - You can open this by clicking Activities and in the Search line, type cmd (short for command), and press Enter.

      Read more about How to use the Linux command line.

    We will be using the command line just for installations but you can use the links to learn other ways to use the command line if you're interested.

    Cannot load image

    Note: Images and videos in this guide will show the Windows command line but the same principles apply to Mac and Linux.

    Once you have the your command line open, type python and hit Enter.

    You should then see information about your Python version meaning that it has installed correctly and you are ready to code.



    You can also now use your command line as an interpreter meaning you can type code and it will be executed. E.g. type 2 + 3 and hit Enter.

    The code will execute and you will see the result in the terminal. You can then type exit() or quit() and hit Enter to exit Python.

    Remember that if you see three greater than signs (>>>), you are running Python in the command line and only Python code will work. If you do not see >>> then you are just in the regular command line and Python code will not work.



    We won't be using the command line to write code (we will use IDLE for that). However, we do need to use the command line to install additional packages.

Pip Installing



    One of the simplest ways to install libraries for Python is through Pip.

    Pip is a package manager for Python packages/modules. Modules are Python code libraries you can include in your project. A package contains all the files you need for a module.

    Pip comes by defualt with Python so you should already have it installed. You can check this by typing pip -V or pip --version in the command line to show the pip version.

    If you see the below error
    --bash: pip: command not found

    Try putting a 3 after pip, like the command below
    pip3 -V

    If that works, whenever you see a reference in the instructions for pip, use pip3 instead.




    To install a Python package, just type pip install <package> in the command line where <package> is the name of the package you want to install.

    Here are the packages you must install for this course.
    1. Numpy - To install type: pip install numpy
    2. Pandas - To install type: pip install pandas
    3. Matplotlib - To install type: pip install matplotlib
    4. Scikit-learn - To install type: pip install -U scikit-learn

    After this you should have these packages with all the necessary files installed.

    You can check what you have installed by typing pip list.



    There are many other useful commands and you can see them all by typing pip.

    You are now setup and ready to use Python, as well as the extra 3 packages, for starting data science and machine learning.