1.1 Jupyter notebook and Google Colab as Spyder IDE alternatives
Oct 8, 2023
I'm a big fan of Spyder as my python IDE. However, some folks like to use Jupyter notebooks or the powerful and free Google Colab. This video shows how to use these alternatives and talks about pros and cons of each like free GPUs vs a built-in variable explorer
Hi, everybody.
This is Taylor Sparks again.
Now, in today's video, I want to show you
a couple of alternatives to using Spyder.
Now, I still think that Spyder is the right tool for you
to use.
It has some key advantages.
But if you don't want to use Spyder,
there are a couple other options,
one being a Jupyter Notebook and one
being Colab, which does Jupyter Notebooks.
So let's show you Google Colab first.
If you haven't heard of Google Colab before,
you can just Google, do Google Colab, C-O-L-A-B.
If you check this out, it'll bring you here
to this page, colab.research.google.com.
When you come here, the landing page
will tell you some stuff, like recent things you worked on.
You can look at examples.
It would probably be good to go through a tutorial
when you first got here.
But let me just briefly show you some things you can do
and what it's good for.
First off, what is Colaboratory?
Colab stands for Collaboratory.
And it is a way that you can write and execute
Python in your browser.
So the fact that it's happening in your browser
means that there is no configuration required.
You don't have to download Python.
It's running in your browser.
The browser is your portal.
And then they have a server on the back end
that has all the stuff downloaded.
So you don't have to worry about any of that stuff.
It makes it really easy to do.
You have free access to GPUs.
So GPUs, graphical process units,
are going to be a lot faster than CPUs for a lot of things
that we need to do in computer science.
And Google offers them for free, which is insane.
And then it's really easy to share these things
because it's part of the Google infrastructure.
So sharing it becomes really easy.
So those are pretty big advantages.
How does it actually work?
When I do my examples in class where
I'm teaching you about variables or whatever else,
how does it work?
So you're going to come over here
and you're going to select a new notebook.
Give just a moment for it to create the notebook.
Now, here what you'll see is the following.
So right here is where you're going
to be able to enter your code.
So in Spyder, that was on the left-hand side of the screen,
and we could write things like import our libraries.
We could import numpy as np.
And great, you can go ahead and run that.
You can keep on typing your entire code.
You could say that the variable x is equal to 5
and y is equal to 10.
And you can see that z is equal to x plus y.
And then you can print z.
So you can do this all inside this, what's called a cell.
And then you can run the cell by holding down Shift
and hitting Enter or by clicking this little button over here.
And then below the cell, it has this sort of output row.
So you see the input and the output.
So it printed z for us.
Or you could do all of those things separately.
You could grab these things.
You could just import numpy in that first cell.
And in the second cell, you could do all that stuff.
And then you could run it separately.
So every time you run your code, you
don't have to keep on importing your libraries, for example.
Or if there was a part of your code that was taking time,
you don't have to run it over and over again.
You can run it once, and then it's just there.
So this is pretty slick.
There are limitations on the data
that you can use, on the RAM and the disk space
that your code can take.
So be aware that that is, Colab isn't free and unlimited.
It has some basic limits.
That said, for I'm sure everything
that we're doing in this class, you're
not going to run into the limit, which is pretty awesome.
Maybe you will.
I don't think you will.
So this is a really cool way to run code.
And if you want to do this in a Python notebook,
that's why the file type is IPyNB.
That's a Python notebook.
If you would rather do that than use Spyder, that's OK.
You can turn in an IPython notebook file.
I can upload that and run it in Jupyter notebooks, no problem.
So this is Colab.
This would be one way to do it.
When you turn this in, you'll still
need to download your Python notebook.
Or it looks like you can download it as a Python file,
which I could open in Spyder.
So I might actually prefer if you did that.
That's one option.
Now let me show you another option.
The other option, you have to download Python still,
but it's called a Jupyter notebook.
And it's pretty cool.
So we start by telling it where we want this to work.
So here's the file directory where
I've been putting all of my Spyder examples
for this class.
So I'm going to copy this directory.
That's important for just a moment.
I'll show you why.
So you're going to grab that whole thing, copy it.
And then we're going to go to our command line
and we're going to type of anaconda.
We want the anaconda prompt.
So here, we're going to do cd.
That stands for change directory.
And then space.
And I'm going to paste that directory.
So this is going to change.
Right now, my standard location is
where I installed anaconda3, which was in users slash Taylor.
But that's not where I want to work today.
I want to work out of here, which is in my Google Drive
teaching 2001.
So we've changed our directory.
Now it looks good.
So now from here, we can just type in Jupyter Notebook.
So capital J for Jupyter, and then Notebook.
Just as easy as that, you'll see that it
starts running some stuff.
It's firing up Jupyter Notebook, which I have an installation.
When I downloaded anaconda version of Python 3,
it came with Jupyter Notebook.
It opens up my browser, because that's
where Jupyter runs is out of your browser, and voila.
Now I'm in that same folder.
You see all the same files that were present in my desktop
folder here.
So I created one here for Python, Jupyter Notebook
example, so for Jupyter Notebooks.
I'm going to open this up.
And it's very similar to what you saw in the Google Colab.
You have cells, and then you have outputs of cells.
I can run this individual cell where I import NumPy.
I can create a variable x and have it equal to numpy.empty 5.
So that's going to create an array with five empty spots
instead of zeros.
And then I can print those.
So I'm holding down Shift and hitting Enter,
and it's just like Google Colab.
So if you prefer this, this is actually kind of nice.
I love that you get to type something,
and then it creates a little output cell right there.
Remember, in Spyder, it was a little bit different.
You typed all your code in one block,
and then there was a little separate window
called our console where the outputs were.
Now, why am I making such a big difference?
Why do I really think Spyder is that much better
if it's just the difference of the output being right here
below the line versus somewhere else?
There's a really, really important difference,
and that has to do with the variable explorer.
So Google Colab and Jupyter Notebooks, to my knowledge,
don't have variable explorers.
Now, I think I did some Googling.
I saw that people have created some widgets
that you can run that create a variable explorer,
but I don't know.
I don't think they're easy to use
if they even are available.
But Spyder does come with them by default.
Now, it takes a little longer to open.
That's a downside of Spyder.
You saw how long it took for it to load.
But check this out.
Here, I'm doing this example for something
for one of my classes I'm teaching.
And so I can run this code.
What's great about it is after I run it,
so again, here's my output.
So if I printed anything, it would have showed up down here,
but then I've got this variable explorer window.
This is super, super valuable.
When I run the code, up comes all my variables.
So I can explore individual variables, right?
This POPT variable.
I can open it up and see that it contains
these two objects inside of it.
If you create an array, it tells me the size of that array,
all just by default.
Whereas if I don't have this variable explorer,
what you have to do in Jupyter Notebooks is ask it.
You have to query it each time.
Like for example,
let's go back to our Jupyter Notebook over here.
Now, because we don't have a variable explorer,
what I have to do instead is I have to query it each time.
And how we do that is I take my X, right,
the NumPy array,
and then I have to do this at this method called shape,
where I'm asking it to return the shape of that.
And then I'm like, oh yeah, okay, this was a five comma.
Okay, right, so you can do that if you want,
but I think that the ease of having it built into Spyder
is just such a big advantage,
being able to click over to that.
Same thing with plots.
You can go back and you can look at a plot you created.
Anyways, my preference, Spyder, but do what you want.
I will happily grade whatever format you turn it in,
whether it's an IPython Notebook,
created in Google Colab, Jupyter Notebook,
or if it's a Spyder file, a Spyder Python file.
All right, we'll see you in the next video.

