Note: please do not attempt to do this yourself, we will go through it together in class. If you miss class, make an appointment with instructor for assistance if you cannot get installation done via instructions.
We will be installing Jupyter in a virtual environment, so that we ensure as a class that we all are using IDENTICAL versions of all python libraries, regardless of what is already installed globally on your machine. Therefore, even if you already have used Jupyter, you will STILL need to ensure you set up a virtual environment that is identical to everyone else's.
We will also be calling Jupyter from the command line so we will set up a few easy steps to ensure that getting to our notebooks is easy and simple (even if you hate command line.)
First, make a folder on your computer where you will keep all our materials for class. I recommend calling it "AudiotechII" or "MUSI2526". We will later create a virtual environment and you can put it in this folder (unless you are used to making VEs and regularly have a different system for doing so.)
Since we will be calling it from the command line A LOT throughout the whole course, I recommend you pick a fairly central folder. However, I will show everyone a shortcut to get there, so if you like to be super organized, and that involves subfolders, go for it.
If you do not have python 3.9 installed on your machine, you will have to install this first. It is OK to have multiple versions of python installed. You can set up which one is the default, and installing Python 3.9 will not overwrite your other versions, nor will it automatically set it to default. These packages were tested with 3.9.9 but any version of 3.9 should work.
Important Notes It is critical that you use a version of Python that is compatible with all the packages we will install. Not all packages are yet compatible with the latest version of Python. For that reason, if you have a newer version of python, you will have to additionally install another (older) version of python, and then select that version when doing our installations, etc. I have tested our environment and it does not work with the latest release of Python (3.10).
I mark with a $ to indicate that this is text you write on a terminal command - you should not literally copy the $ symbol.
Open a terminal. Type the following to check whether you have python 3.9 installed on your machine:
$ which python3.9
If you have python3 installed, your system should return the directory where it is located. If you get an error message (or empty output), then you do NOT have python 3.9 installed and will need to install it.
If you already have python 3.9 installed, you can skip to step 2. Otherwise, proceed with installing Python 3.9. Note that your system can handle having multiple versions of Python installed globally with no problem.
The best way to install python3.7 is with the package manager, homebrew. To see if you already have it installed, you can open a terminal and type:
$ which brew
If it returns a directory, then you already have it installed. You can first ensure you have the most up-to-date version by typing in your terminal:
$ brew update
you can now simply execute the following to install python 3.9:
$ brew install python3.9
If homebrew is not installed, go here and follow the instructions. OR, you can just download directly from here BUT: Be sure to check the box that says Add Python 3.9 to PATH!!
Open a command terminal (win+r, then type ’cmd', then Enter). In the terminal type:
$ py -0 ## That's a zero, not the letter "O".
This should list all the available python versions you have installed, and should have an asterisk next to the default version. As stated above, you need a version of 3.9 (ideally 3.9.9). Note: You might have 64 or 32 bit, this is machine specific so you should check whether your machine has a 32-bit or 64-bit processor (most are 64 bit now).
If it says "no such command" then you have no versions of Python installed on your machine.
If you already have python 3.9, you can skip to step 2. If you need to install it, keep reading.
Simply go here and follow the instructions for your machine (you probably want the "executive installer". BE SURE TO check the box that says Add Python 3.9 to PATH!!
Creating virtual environments is a good practice. It ensures that any package components are isolated and don't interfere with packages and libraries installed elsewhere on your machine.
The first step in creating a virtual environment is to navigate to your class folder where you will place your new virtual environment.
To navigate to it from the command line:
On Mac or Linux, you can navigate like this:
$ cd /path/to/folder
On Windows, the slashes are backwards:
$ cd \path\to\folder
The package manager "pip3" should have come bundled with your installation of python3. (If somehow you already had python3 and not pip3, you'll need to look up how to install it.)
Next, we need to make sure we have the tool installed for creating a virtual environment. We'll be using virtualenv.
$ pip3 install virtualenv
Warning: Windows users must run CMD as admin. Search CMD and right click -> run as administrator
Note: if on Windows this still doesn't work, first try exiting the CMD program and opening a new one (as admin). If that still doesn't work try pip instead of pip3 in the above command.
In order to create the virtual environment, we first (one time only) need to execute a script that will create the virtual environment, which will automatically create a direcitory (and also create subdirectories inside it containing a copy of the Python interpreter, the standard library, and various supporting files). You can call this environment whatever you want, but but I recommend calling your environment "at2venv". (Also, if you use virtual environments a lot, and you always use the default "venv" you can easily get confused.)
Next:
First, make sure you have navigated to your new class project folder on the command line see the "cd" instructions above for each type of system.
You can then run the following:
$ virtualenv --python=$(which python3.9) at2venv
If you get an error at this stage along the lines of "command virtualenv not found" then try this instead:
$ python3.9 -m virtualenv at2venv
First, check that virtualenv was successfully installed by typing:
$ where virtualenv
If this query returns ``Could not find files for the given pattern(s)'' then it has not been installed properly. If this happens, reach out to me for assistance. Else, if it returns a directory, you're good! Continue!
Next, identify the location of your python installation:
On the CMD command line, type $ where python3.9 or $ where python3 which should return a directory likely with ``Program Files'' in the name. Copy it. (Careful to examine the full directory path here: it should have "Python39" in there somewhere or else it might be the wrong version.)
search "python". Open file location, open folder, right click on the shortcut to python3.9, open properties, copy path from "target" box. (it should NOT be in your downloads!! If so, abort!)
Enter that entire path into the command below between "-p" and "at2venv" (if copying from command line be sure to put double quotes around the directory path)
Ensure that you are already in the project folder you created for class. Then:
$ virtualenv -p \path\to\python3.9\windows.exe at2venv
OK, this should have created your virtual envionment, but not yet activated it. If you have never worked with virtual environments before, it's very important that you understand you have to activate the virtual environment to be able to work inside it. Do to this, we have to run a script...
Make sure you're in your class folder. Once inside the folder, to activate the virtual environment, you'll run:
$ source at2venv/bin/activate
$ .\at2venv\Scripts\activate
You should now see the name of your folder in parentheses before your current path. This lets you know that you are inside the virtual environment. When in this state, anything you install will only be installed inside this "container" we created which is the virtual environment, and it will not interact or interfere with other packages on your system.
You can confirm the location of your python interpreter by typing:
$ which python on a Mac, or $ where python on Windows machines. It should point to the env directory.
Go to Canvas and download the file called "requirements.txt" and place it in the project directory.
IMPORTANT: Make sure you are in your project directory and you've activated the at2venv environment (you should see the parentheses).
You can now go ahead and install all the libraries required for this class (for now) by typing:
$ pip3 install -r requirements.txt
Warning: Windows users may encounter more difficulties than Mac users during this process. If you are experiencing a lot of errors, you will need to reach out to your instructor or TA for assistance.
At this point you should now be able to open Jupyter notebooks from your command line. The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Now that you have installed Jupyter, a Jupyter notebook can be executed on a local desktop requiring no internet access. It supports many coding languages but we will primarily be using python.
I strongly recommend you overview this document if you are new to Jupyter notebooks.
From your activated virtual environment, you should now be able to type on the command line:
$ jupyter notebook which should open a local host to your directory in a web browser. From here you can click "new" and click on "python3" to open a new notebook.
This is what we'll be using in this course for delivery of materials to each other (i.e., most of my lectures, your homework, assignments, and projects.)
For a page with handy shortcuts, see (https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/)
When you are done working in the virtual environment at the end of your work sessions, you should get in the habit of deactivating it by typing:
$ deactivate
This removes you from the virtual environment. Note that anything you installed inside the virtual environment will no longer be accessible to you, like Jupyter (which is a good thing).
You'll be using the folder that contains your virtual environment a lot for this class, and if it's buried away under several subfolders, that might be annoying. Consider adding a simple command to your .bash_profile file (or .zshrc file if you use zshell).
Check to see if you already have a .bash_profile file. It should be located in your home directory.
$ ~/ls -a will list all files including hidden ones. Hidden files start with "."
Open the file with any text editor and add the following line somewhere in the document (probably at the end is best)
$ alias name-of-shortcut="cd ~/location/of/your/project/folder" where "name-of-shortcut" is the command you want to type, and everything after the tilde is the path to your project folder.
If you then exit out of the terminal and open it again, you should be able to type your shortcut from any directory and it will take you straight there.
Note: if you don't have a .bash_profile file, you can create one using any text editor.
To make it easier to work with our class files, I suggest you download the zip folders on canvas called "uploaded_files.zip" and "images.zip" and (unzip and then) place them in your class project folder.
All the sound files are in "uploaded_files" so if you want to follow along with my coding in class, you can call yours by the same name, or else just remember what you've called this folder of sound files.
For setting default figure size (plot) settings for all notebooks, you must alter the following file: ~/.ipython/profile_default/ipython_kernel_config.py
Change (or add) the following lines:
c.InteractiveShellApp.matplotlib = 'inline'
c.InlineBackend.figure_formats='svg'
c.InlineBackend.rc = {'figure.figsize': (12,4)}
(alternatively, change the X and Y parameters of figures to be whatever you want.)