00:00:00

Bootstrapping Python

Notes

What is this course about?

Learn how to ...

  • install Python on your computer
  • install Python libraries
  • start and use Jupyter Notebook

Notes

What is Python

  • Python is an interpreted computer language
    • An interpreter is required to run code written in such a language, which means ...
    • We need the Python Interpreter to run Python code
    • Sometimes we use the word Python to mean the language, sometimes the interpreter
    • Latest version of the Python Interpreter is version 3.7
  • We will learn how to install the Python interpreter

Python Logo

Notes

Introducing Anaconda Python

  • Anaconda Python is a popular distribution of the Python Interpreter
    • It contains the Python Interpreter, and many useful "goodies"

Anaconda Analogy

Notes

Installing Anaconda Python

Notes

Installing Anaconda on Windows

Windows Icon

Follow the official instructions

Notes

Installing Anaconda on Mac

Mac Icon

Follow the official instructions

Notes

Installing Anaconda on Linux

Linux Icon

Follow the official instructions

Notes

Confirming that installation is successful

Windows: launch Anaconda Prompt from the Start Menu. Mac: launch the Terminal app. Linux: launch a terminal.

At the command prompt, enter python and hit ENTER. To exit Python, enter exit() and hit ENTER.

Windows Prompt

Mac Prompt

Notes

Introducing virtualenv (!)

  • Think of a virtual environment (virtualenv) as a sandbox'ed Anaconda installation.
  • Advantages:
    • You can afford to experiment with things and mess it up, e.g. by installing experimental libraries - simply delete it and re-create one
    • You can set up multiple virtualenvs for projects that might need conflicting version of Python and/or libraries
    • Some libraries require a virtualenv to work properly.

Notes

Creating a virtualenv

At the command prompt, execute conda create --name py37 python=3.7 jupyter

When prompted for yes or no, enter y

The command above does the following -

  • Creating a virtualenv named py37.
  • Giving the virualenv the Python v3.7 interpreter. (The actual version installed depends on the latest revision number, e.g. v3.7.1)
  • Installing the jupyter library. This library will provide the Jupyter Notebook we will be using later.

Notes

What it looks like

Conda Create

Notes

Using virtualenv

On Windows, Anaconda Prompt's command prompt always shows the current virtualenv in use. When the root environment is in use, it displays (base).

On Mac or Linux, the terminal will not show anything when root environment is used.

To change to our newly created environment, execute conda activate py37

Conda Activate

To exit the current environment, execute conda deactivate

Notes

Using Jupyter Notebook

Notes

Starting Jupyter Notebook

Activate our environment at the command prompt, and then execute jupyter notebook.

Jupyter Notebook

Notes

Creating a folder

Click New on the upper RHS, and select Folder from the dropdown.

Jupyter New Folder

Notes

Renaming the folder (NO SPACE)

Check the folder to be renamed, click Rename on the upper LHS, and type new folder name WITHOUT SPACE.

Jupyter Rename Folder

Notes

Creating a notebook

Click on the folder you just created. Once inside, click New on the upper RHS, and select Python 3 from the dropdown.

Jupyter New Notebook

Notes

Renaming the notebook (1st thing 1st)

Click on File and select Rename from the dropdown. Type in new name WITHOUT SPACE. Note: leave the folder name before the / alone.