Kursmaterial
We'll use jupyter
during some of the lectures and labs. It's a great piece of software,
and I really think it could help you a lot when you take this course,
but I'll also generate regular web pages with the problem sets for the
labs, so you don't have to download and install jupyter
.
To install Jupyter on your own computer, see "Installing jupyter
on your own computer" (just below).
Jupyter is installed on the Linux computers in the E-building. To run SQL queries in it, you need to do two things – see "Using jupyter
at LTH" further below.
You can find instructions for installing jupyter
on their web site. To run sql
inside our notebooks, we also need ipython-sql
, we can install it with:
Some of you have reported that you get the error:
ERROR:root:Cell magic `%%sql` not found
Look below to see why this happens.
After you have installed jupyter
, you can download and
unpack the notebooks distributed on the course web site, start a
browser, open a command line interpreter (shell), go to the directory
with the notebook, and run
You can also run jupyter lab
, but it will probably not make much difference for this course.
Jupyter will open a tab in a browser, and there you have to select what notebook to run – the notebooks are the files ending in .ipynb
.
For each cell you want to evaluate, activate the cell (by tab-ing
your way or clicking), and press Shift-Enter. Each cell can only contain
one SQL command (prefixed by %sql
or %%sql
), but you can easily insert new cells in the menu above (the +
-button creates a new cell below the active cell, and the Insert
-menu has commands for inserting above and below the current cell).
Some of you have reported that you get the error:
ERROR:root:Cell magic `%%sql` not found
It's probably because you haven't evaluated the
cell (it's normally the first cell). Also make sure that you import any relevant database by evaluating cells like:
I'll talk a bit more about jupyter
during the first lecture (I'll also show you the command jupyter lab
, which is similar to jupyter notebook
).
In Spring 2021, the course was given remotely, so the instructions below are those given in the spring of 2020, and they should still work – please let me know if they don't (these days almost all students use their own computer for this course, and we don't want to invest too much time into setting up systems which will probably not be used).
TL;DR: If you use bash
as your shell (I think it is the default on LTH), you can just paste the following two lines in a terminal window:
Now close the terminal window into which you pasted the text above, and try to run jupyter notebook
from a new terminal window. You only have to run the commands above one
time, and all future terminal windows should be able to start jupyter
with support for SQL queries.
Slightly longer explanation (in case you have changed your setup from the defaults at LTH): You don't have to install Jupyter on the Linux computers at LTH (it's already installed), but to use SQL from your Jupyter notebooks, you need to do the following two things (you only need to do it once, then it should work the next time you log in or open a terminal window):
We need to make sure
/usr/local/anaconda3/bin
is on our$PATH
(i.e., where our command line interpreter looks for programs to call):I recommend you put the line above in your
.bashrc
- or.zshrc
-file (depending on whether you usebash
orzsh
), so your shell always can findjupyter
. If you usebash
as your command line shell (I think it is the default shell at LTH), you can paste the command below in a terminal window:In a terminal window, paste the command:
This installs
ipython-sql
on your own account (you're not allowed to make system wide upgrades).
After these two steps, you can follow the instructions for running the notebooks below (first close your terminal window and open another one).