Transcription
All right, so my last video, um, we installed K. We have it here as the base. Um, normally the next thing I would want to show you is Jupiter Lab, but what I actually want to show you is how could you use K specifically in VS Code, because that's where you're really going to want to use it. Um, also in Jupiter Lab, of course. Um, and so, you know, we just need some kind of random project to work on. And so I'm just going to go here and make a new, um, uh, file. So I'm going to go back here for a second, and it really doesn't matter what it is. So I'm just going to say `mkdir hello` and I'm going to `cd` into `hello`. And I'm just going to open this up in VS Code. So I'm doing `code .` If you don't have that installed, it will install it and then it will let you open it up like this. Close out the old one so you just don't get mixed up. That can get kind of confusing if you don't do that.
I'm going to go ahead here on the right hand side. I'm going to make a new file called `app.py`. Okay. And so if I open up terminal, notice that `conda` is loaded as we see the word `base`. If you don't see that, then there's something wrong with your installation. You have to fix it. The other reason you might not see it is if you install some kind of fancy thing that, uh, colors or or makes this more convenient, it could overwrite that. So you could still have it there, but just consider those could be issues that you're having.
So, you know, every time you work on a project, you should create a a separate environment for each one. Absolutely, you should do that. Um, and don't work in `base`. I try not to install anything in `base`. If you do, there is a way to clear out `base`. I don't do it very often, so I'm I'm not sure in this video, but you can do that. But try to keep `base` as clean as you can. But it's going to happen where you're going to install things in there by accident, which you don't mean to do. But the thing is that different environments can inherit from `base`, and so that's why you don't want to muddy your `base`.
Um, but what I want to do is I want to create a new environment. And I honestly do not have this memorized, so I often have to look it up. Um, so just a moment here as I'm looking for, um, the GitHub repo we just had open here just a moment ago, which is here, here I believe. And so I'm going to have this off screen and and I'm going to look smart by pretending that I remember this, but it's `conda create --name hello python=3.10 -y`. And we'll hit enter. And so it's going to go ahead and create ourselves that environment. We need to activate it. So we type `conda activate hello`. Again, this is something we're going to do again and again and again, so just get used to it.
Um, so the idea is we want to run something here and we need some kind of library installed. And so we can install it a few ways. One way is using `conda-forge`. So `conda-forge`, um, we go here, are basically trusted libraries, um, that are configured for use. We go over here, `conda-forge`, and so we can explore it. And no, I want the packages here. Here we go. So these are all the possible packages that we can install. Now we can install things outside of `conda-forge`, but I'm not really seeing the ones I want. There's too many packages, right? So if we wanted PyTorch, we type in PyTorch here, right? Whatever we want. If we wanted, um, uh, scikit, scikit, I'm not sure why I'm having to hard type typing it in today, but the point is, or like pandas, if we want pandas, it's there. And so let's say we wanted to work with pandas, right, right. Um, we could, we could do a `pip install`, and sometimes you do that, but you really want to try to always do `conda`, `conda-forge install`. So I'm going to go over to here and maybe we'll continue on here, um, with this. So we had `conda`, I'll just call this one setup. I'm so bad, I just keep renaming these on you folks. Uh, we'll say `hello_example`. And so what did we do so far? Um, oops, I want a `README` here. What did we do? We we said `conda`, um, or `conda create -n hello python=3.10`, hyphen `y`. That was our first command. And then our next one was `conda activate`. So next thing we want to do is we want to install. So I think it's `conda install -c conda-forge`. So what we're saying is like, we want to install something, but specifically use `conda-forge`, and you could specify other things here. I just don't know anything besides `conda-forge`, so I often just type that in. And so we would do this. So we'll go ahead and give this a try, right? And that is not what I wanted. So I'll just type it again because copying between, um, remote, like remote desktop doesn't always work properly. So I'm just going to type it fully in here. And we'll type in pandas, right? So this is now going to install it here. Now we could also create a `requirements.txt` installed, and that's totally fine as well, but sometimes you want to install libraries this way so you absolutely know they're coming from `conda-forge`. Okay, so we give it a hyphen `y` here, and so that's installing. So that's going good. And so now we have `conda-forge` installed, or sorry, pandas installed. Um, I'm not sure if it would show up under `conda info`. We can take a look here. So I don't think it would show those libraries, but if we wanted to see what packages we had, right, we do, um, is it `pip show`? I believe `pip show`, or sorry, `pip list`. And so here we can see we have, or sorry, pandas is installed here.
So what I want to do is I want to do `deactivate`. Let's take a look here and we'll do `pip list`. And notice this comes with a lot of stuff installed, but does it have pandas installed? It does not, right? Because this is the `base` one that's installed here. I'm going to go back over to `hello` and we'll do `conda`, or sorry, `pip list`. And I think I said earlier that I, I believe that, um, things inherit from `base`, but but it doesn't appear that way. So I guess that's just a false statement. Each environment is completely isolated, and that's actually a lot better. So here we have pandas. And so if we want to use it, let's make some pandas code here. Um, I don't want to figure it out. I'm not great at pandas, so I'm going to go over to ChatGPT or whatever you want to go to, whatever free, uh, model you want to use. I'm just over here. I'm just give me like, give me a basic, uh, example of pandas. Okay, we'll go ahead and do that. Should be using mini because I get limited uses of GPT. Oh, one. And we'll give it a moment here. We've already installed it, so I'm going to grab this as an example. You do whatever you want as a basic example. Okay, we have a basic data frame. We just want to make sure that it works. That's all that matters to us here. Okay, so we have this here. I'm going to go ahead and I'm going to, um, run this. So if I do `ls`, we have the `app.py`. Uh, so do `python app.py`. And notice that we can use the word `python` as opposed to `python3` because it should be routed to that location. One thing you might want to check when you're using Python is where it is. So say `where is python`. And so it's showing that it's loading for Miniconda. There have been cases where I've had to use `python3`, which is kind of annoying, but we can type that in as well. Say `where is python3`. Sometimes both are installed, sometimes only one's installed, but you can see that, um, it looks like Python 3, there's probably a local one here. So the local installed version outside of conda is that one, but clearly we want to use Python. Uh, I know it's confusing, but it's just how it is. But anyway, I think that worked, right? Did our file work? It did. Okay.
So if you want to run this as well, I'll go copy it over here to our, uh, repo over here, `app.py`. And so we'll go back over to this and we'll just do a bit of documentation. So we had `conda install`, we had `conda`, uh, or so we had `pip show`, or sorry, `pip list`. Then we had `conda deactivate`, and then we had `pip list`. We have, uh, `conda activate hello`, and then we do `python app.py`. Okay, so this is, um, `hello_example`. And so here we are creating our, uh, `hello` environment. We, uh, install pandas in our, uh, `hello` environment. We observe which packages are installed. We observe which packages are installed in `base`. It's good to make notes. Like, even if, like, this is really simple, just going through the habit of doing this really helps commit it to long-term memory for yourself. Um, and so I just, that's why I always do this. It's kind of like your opportunity to do it, like, two, three times over. Um, we can use the Python, Python binary to execute the Python in the context of conda. And we can type in `where is python` to check, check which, uh, uh, what binary is being loaded. Okay. We do `where is python3`. One thing we might also want to check out is like, what if we did a, uh, `requirements.txt` here? And we're not using the forge, it should still work. Okay. And so I need some kind of library here. We just say `torch`. And so I'm going to go here and do `pip install -r requirements.txt`. Okay, so it's installing, no problem here. I maybe I shouldn't have installed torch because that takes a bit of time. Yeah, it's a little bit large. So I'm just going to stop that. And you'll notice like torch is almost like, um, a gigabyte. So you might want to clean up your environments from time to time. Maybe I should have chose something smaller. Um, you know, like `python.env`. We'll end up using that quite a bit. So `python.env`. So do, um, `pip install -r requirements.txt`. So it'll install from that file here. Okay, so that's really good. Um, I'll go back over to here and I'll just make a new requirements here. Uh, this will be just `python`. Just again, writing it again, `python.env`. That's so we can load environment variables. And actually, we'll use that quite a bit. So that one's a good example to have here. We'll go back over to our `README`. What else did we do? We did, um, uh, `python`, or sorry, `pip install requirements.txt` has have a hyphen `r` in front of it. If you forget it, don't worry. Like after a week of me not working with Python, I always forget that command. We'll do `pip pip list` again here because I want to see if it installed it. So we have `python`, `python.env` here. Another thing that I should show you is, um, working with not Jupiter Labs, but it's the environment specifically for, um, VS Code. So we'll do that in the next video here. And so I'm just going to stop it. I'm going to keep this environment around because this one's actually useful for us. I'm going to go ahead and just quickly commit, uh, this code here so we have it for later. Not sure if that's really the right commit messages, but no one judge me on my commit messages. Okay, see you in the next one.