In this video, I'm going to show you how to start up the Jupyter environment that we're going
to be using for our Python program and write some of our first Python code.
Also walk through the steps needed to turn a notebook into a PDF
you can submit on blackboard for one of the assignments. So I've already installed Anaconda.
You can find the instructions for that on the course Web site. On Windows, when we've installed in ancondo, we get
a new kind of prompt available in the START menu. So I can go in to start the anaconda power shall prompt.
And this starts up a power shell command line
that has Anaconda activated. The process for doing this on Linux or on Windows is slightly different, although excuse me,
on Linux or on Mac is slightly different, although you can also start the prompt from the Anaconda navigator.
I will show you in another video how to activate Anaconda when we have it installed on Onyx, which will also apply to other Linux systems.
So I'm in my anaconda prompt, it's in my home directory. I'm going to go to the directory I've created for working on C.S. 533.
So I'm going to cd into documents\CS 533 assignments, and here I'm going to start the Jupyter environment with Jupyter notebook.
So we're gonna be doing our work in what we call notebooks. They're a part of Jupyter. We can start this at the command line with Jupyter notebook.
And it's going to start up the Jupyter system and open it up in our Web browser.
The Web browser is the interface that we use to interface with Jupyter and interact with notebooks.
So if I had some notebook files in here, they would be listed in the notebook list and we could open them.
So in the assignment, you'll download the starter notebook. Save it in the directory you're working in.
When you run Jupiter notebook, it will appear. But right now, I'm one to create a new notebook.
I'm going to create a new Python 3 notebook because Python 3 is what we're using in this class.
And it's a new notebook and it's untitled. So I'm going to given a name here.
I'm just going to call it demo notebook because it's the notebook that I'm using to demonstrate.
If I go back to our notebook list, we now see it and its "Demo Notebook.ipynb" the ipynb file as the source filed for the notebook.
You're going to be submitting those as one of the things you submit in your assignment. So now a notebook is made up of cells.
And right now we have one cell here. So I want to put some code in it.
I'm just going to write the string "Hello, world". The string isn't close in case, and it's enclosed in double quotes.
And I am going to hit shift enter. And that run - shift enter - runs the cell that we're currently in.
And now it's labeled In [1] . It's the first cell that we ran. And it has an output Out [1] that says, "Hello, world"
When you run a cell and the last line of the cell is an expression that has some value, what Jupyter will do is it will show you that value.
So because the last and only line of the cell is the string value
"Hello, world" It shows me the value. "Hello, world"
If I put in a value - a number - five, it will show me the number five.
It only prints the value of the last line, but it lets us very quickly just see an object.
We don't even need to worry about print statements. If we do want to create output, we can
call print, and it will print the output for the way Python would usually print it.
It shows up as a as as text. Jupyter is going to show the output of our program here.
It's formatted a little differently because its output. It's not just showing the results of an expression.
These code cells are not the only cells that we can have in a notebook.
So I'm going to insert a new cell above the above this one.
And I am going to change its type to markdown.
And in a markdown cell, we don't write python code, but we write text.
So I wrote the text, this is the demonstration node to show notebook to show you how to run Python code.
And if I run this notebook, it just renders it as text.
Now I can edit it. I'm going to double click to edit it again.
This supports all markdown features so we can give this notebook a heading.
We always want to begin our notebook with a level one heading, which is done with a single hash that gives the title of the notebooks,
that then when we convert it to another format, we're gonna have the title right there.
Markdown cells support a variety of formatting features.
Such as bold and italics.
Also, bulleted lists. Lists and numbered
lists. I'm going to stick another cell in here. I use the menu -
I can also hit the A key and it will add a new cell above and M changes it to mark down.
There's keys that will that will let us navigate the notebook quickly.
Also, the notebook is what we call modal.
If the if - the interface has two modes, if the cell is surrounded in green, I'm editing the contents of this cell.
We can also show mathematical expressions like y = mx+b, you put them in dollar signs and they're going to be rendered.
I'm going to shift enter again. And now the math is showing up like math.
When it's blue, when the cell is highlighted in blue, we're not editing the contents of the cell, but rather we are moving around cells.
So the up and down arrows, keys like a will add a cell instead of typing a in the cell.
Once we're on a cell, we can hit enter to edit the cell and escape to change back to the mode where we navigate cells.
So now we have this notebook control as saves the notebook. Jupiter has its own set of menus so we can do a variety of things like again, save
save the notebook with a new name. We can make a copy of The Notebook.
We can also we're going to go submit the notebook - in order to give you feedback -
I want a PDF of your notebook so that I can use blackboards, PDF markup tools to give you feedback on your assignments.
So, Jupyter has the direct ability to create a PDF, but unfortunately requires an entire LaTeX installation.
An additional software on top of that in order to go from a notebook to a PDF.
So what instead we're going to do is we're going to go into the notebooks print preview.
So I clicked file on the notebook interface. I go to print preview.
This shows a trimmed down version of The Notebook that's not interactive.
It doesn't have any in the interface. And now we can print this version of the notebook.
And we can print your browser is going to let you save as a PDF when you go to print.
So we're just going to use that save as PDF. I'm going to go put it in my assignment's directory.
Demo Notebook.pdf . I'm gonna dlose this window.
Now, if I go to that directory, I'm going to see both my ipynm file.
That's the actual notebook file itself and the PDF file I just exported.
I can look at the contents of that PDF file and it looks like we expected.
We see the notebook title at the top where he wrote that level one heading.
We see all of our output. When you're submitting an assignment
what I want you to submit is both the ipynb file and the notebook file.
So now. So when we're done with a notebook, then we go what it this file menu and we close and halt.
And this closes the notebook tab. But it also shuts down the python instance that's running in the background to let us run the code in the notebook.
If you don't close a halt, you're going to wind up with a bunch of python instances kicking around that you may not want.
We're gonna see more features of Jupyter as we go through the class, including things to manage the python processes that are running.
But now you've seen the first steps to how you can open Jupyter.
You can create a notebook. You've seen notebook cells and you've seen how we can take this notebook and create output
you're going to submit when you submit the results of an assignment.