Supplementary

This lesson will cover how to install a package manager and a package locally. Our focus from the beginning has been to get you exposed and learning right away about data science. We didn't want to bog anyone down or lose motivation as they tried to set up their own programming environment and run into some difficulty along the way. This is because installing an environment requires knowledge outside the scope of our course, such as what Unix is and how to use a terminal. As such we've left this lesson until the end and made it optional for those that feel comfortable doing this on their own.

Recall in the Interpretation lesson that we learned Python is a programming language that allows us to convert text such as print("Hello World") into the zeros and ones that a computer understands. So to write Python code all we really need is any text editor, however we need some interface to run Python programs. This can be done in any terminal window that comes installed on your computer, called Terminal in Mac and Windows Command Line for Windows, however there are other programs that make the interface easier, two of these are Emacs and VS-Code.

Let us use Seaborn as the package we wish to install. But before we do that, we must go through the following steps:

  • Figure out where we should be coding
  • Understand the difference between operating systems
  • Set up our Python environment

Part of the reason we left this lesson for the end is due to its use of a terminal. A terminal is as old as programming. It is an interface into the mind of a computer. To proceed with this lesson, we will assume a passing familiarity with a terminal, or at least know how to open one.

We will also assume you are in a Unix environment. Unix has a long history of being more stable with better permissions management than Windows. MacOS is a derivative of Unix and as such, commands that work in Unix will typically work in MacOS; however care must be taken to make sure installed programs are for MacOS and not Unix. Windows is the odd system out. It's getting better thanks to WSL2 (Windows Subsystem Linux), that is a highly integrated virtual environment in Windows that allows one to operate just like a Unix user. For Windows users, it is left to the reader to set up WSL2. Though this process has gotten significantly easier in the last few years. Here's a link that covers installation: https://learn.microsoft.com/en-us/windows/wsl/install. After installation, one can install various Unix flavors, such as Ubuntu 22.02. Within this environment one can follow the Unix code.

Start by opening a terminal. On Mac this is called Terminal. On Unix, this comes in different names, but is very similar. One should see a screen that is similar to below.

Our first plot: Point plot

Python has a number of popular package managers, the two biggest being pip and anaconda. The packages offered in each of these repositories typically have high overlap, so it's a matter of preference on which one wants to use. However for consistency it's typically best to chose one and use it for sourcing all packages. This course will use anaconda for handling its environment and packages.

Please use the dropdown to follow code for either MacOS or Unix. The installer for Mac is also dependent on whether your system is using new Apple silicon such as M1 or M2, or older Intel based CPU's. This installation will install miniconda (a smaller, more portable version anaconda) and set up an environment to protect your computer from you. When running the installer, follow the prompts to the best of your abilities. When it asks where you want to install it, it's up to you where the new directory miniconda3 will be installed, however pressing enter is a default location and might be safest to start. When it asks if you want to run conda init, please input yes.

What this is doing is downloading a miniconda installer, running the installer, refreshing our terminal so that it can find the installed program, creating a virtual environment called cafeVenv and entering this virtual environment.

If you had trouble, please reference the miniconda installation site https://docs.conda.io/en/latest/miniconda.html and do the best you can to install miniconda on your system. As the focus of data science is to work with data, don't feel like you have to get this working right away. Getting a coding environment set up is one of the hardest things any programmer will do when they start learning a new programming language.

Let's assume you've successfully installed miniconda and are in the virtual environment cafeVenv. Please double check you are inside the cafeVenv environment and not the default environment base. This will likely be displayed somewhere on your terminal. This is because any packages installed outside the virtual environment will not be available inside. Similarly, any installed packages inside will not be available outside or in a different virtual environment. Anaconda contains numerous repositories within it, such as anaconda and conda-forge, so it's best to Google search the right terms to install the package you want.

We should make sure Python installed properly. It's possible miniconda will not install any verson of Python and leave it to the user to install it. Enter a Python session by simply typing python in a terminal: if it says program not found, then we should install it using the code below.

After installation, try entering a Python session again. If you are able to enter a session, one can exit via inputting exit() then hitting enter, or the keys CTRL-D, where CTRL stands for the control button on a keyboard and the dash indicates the two buttons should be pressed together, and a capital d is more for notation, it doesn't have to be capitalized.

To install Seaborn, use the code below.

Running this in a terminal will install the Seaborn package into the virtual environment, making it able to be imported by any program that wants to use it. It is important to note that this package is only available while in this Python environment. If one changes environment or returns to a global Python, this package will not be available.

If one wants to exit the virtual environment, simply input in a terminal.

Excellent! We hope you've gained some knowledge and confidence in this course. To a brighter future!