How to use a Python Virtual Environment the RIGHT way with Jupyter Notebook

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's going on folks welcome back to another video so in today's video I'm actually going to show you how to go ahead and use Jupiter notebooks within a virtual environment now I was actually approached by a few people on reddit and on Facebook that were asking me they were saying hey listen I'm following some of your instructions and some of your previous videos but for whatever reason things aren't working out on I don't understand why and one of the things they were doing is when they were opening up their Jupiter notebook they weren't actually opening it up in a virtual environment colonel and so I'm gonna show you how to go ahead and do that so first thing what I'm gonna do is I'm gonna create a brand new virtual environment direct room it's gonna create a brand new directory on my desktop and then in that what we're gonna do is we're gonna do two things one is we're gonna open up Jupiter notebooks the way that people have been opening it up and realizing that things aren't working out exactly and then we're gonna open up Jupiter notebooks using a virtual environment Colonel I'll show you how to do and then we're gonna import a library we'll import something like pandas and I'll show you that the versioning is actually different between the two so let's get started right here so first things first let's go ahead and I'm just gonna put this on my desktop so let me CD into my desktop alright so let's go ahead and make a folder so we're gonna say make durand we're just gonna call this virtual test so let's just call it that will go CD into virtual test just so that everything is contained in one place and my desktop is going to be exploding so ILS until there's there's nothing into it and that's what I want so the next thing when I go ahead and type is I'm gonna go ahead and type in virtual a and V V and V and I want to specify that this has got to be Python 3 so it's going to go ahead and create everything for this once we do that we're gonna go ahead and activate our virtual environments I'm going to type in source the env bin activate all right so now it shows that I'm in my ven b because obviously it says ve and me in front of it so that means I've in my virtual environment now here's the mistake people make they go ahead right away in the type and Jupiter notebook thinking that by doing so they're actually gonna go ahead and open an instance of Jupiter notebook in their virtual environment which is actually not true so they're what they'll do they'll hit you know new Python 3 and then if I were to go ahead and just take a look at the Python version or sorry the version 4 pandas so if I were going to go ahead and do this and I type in import pandas as peedee peedee underscore version this is gonna tell me the version of pandas now it says zero point two five point two well the interesting thing here is in my virtual environment I've actually installed nothing so if I go back to my virtual environment so I'm just gonna start a new desktop page here we're gonna go back into our I'm gonna CD back into that folder so we'll just go to virtual tests that's where it was and so I've got VG and V so I'm gonna go again into source the E and V bin activate again and so if I do a pip freeze here well I actually have nothing installed so I don't know where this is actually getting to point zero point two five point two now that's a version which is the latest version I have installed on my actual computer but not in this virtual environment so here's what we're gonna do we're gonna go ahead and we're gonna install pandas but we're gonna install an older version so I'm gonna say pip install pandas and we'll say equals equals zero point two four point two because I know this version exists now it's gonna go ahead and install all this for us which is gonna be good then we're gonna run that command again and technically speaking so now let's just rule out the fact that I didn't have it installed in my virtual environment and now when I do I'm gonna go ahead and go up here and I'm gonna restart this kernel and technically speaking if I am in my virtual environment this should say two point four point two well it doesn't update well what that tells me is that I'm actually not in a virtual environment and that's why when a lot of people are copying over all this code and they're trying to run it they're copying over the code and they're copying over all the versions in a virtual environment but they're actually not running their panda's instance in a virtual environment so let me go ahead and show you how you would go ahead and run this in a virtual environment and just as a quick segue be sure to also check out our partners Nord VPN I've been using their service for VPN services for well over almost five years now and I have not been disappointed check out they only also have a 70% offer link is going to be in the description check it out they've been fantastic great customer service and overall great service as well to keep you safe online as you serve now the next thing you need to do is you actually need to go ahead you know as I go back into my terminal file as I'm sitting in my virtual environment here there's a few other things I'm going to do so let me make this a little bit bigger for us to see I actually need to go ahead and install an instance of ipython and in order for me to do that I need to go ahead and and install ipython inside my virtual environment so my virtual environment is called V env like we decided so I'm gonna type in ipython kernel install user name equals V E and B all right so then it says installed kernel spec ve and V in all of this so basically now in my virtual environment I should have a kernel which I've called V env so let's go ahead and fire up Jupiter notebook again alright now as they fire up Jupiter notebook what I'm gonna do is I'm gonna go to new but this time I'm gonna go to ve env because that is the virtual environment that I've got the call so instead of going to Python 3 which is just gonna default to my system version of all the different packages that I got I'm gonna go to ve and V then I'm gonna bring in the exact same code as before I'm gonna bring an import pandas as PD and then type the version number so now in this one you see that it's zero point two four point two and so if I go ahead and bring up my virtual environment so I'm gonna actually close out of this because I've showed you that that's the version number but just again to remind you if I were to go ahead and bring up my regular environment and type in Jupiter notebook and I go went ahead and I just picked Python three and I use that command again just to remind you this is going to show zero point two five point to where this shows zero point two four point two this tells me that I'm in my virtual environment which is also represented right up here as well so guys hopefully you find this tutorial helpful again very quickly to show you to make sure that when you are downloading code from github or when you're downloading it from different source sources or sites and when you create your virtual environment you want to make sure that if you are going into Jupiter's sublime did you know regardless of whatever tool you're using you want to make sure that you're in your virtual environment you're using the packages that are installed in your virtual environment and your IDE is actually connected to your virtual environment so hopefully you found this tutorial informative and if you did please consider liking and subscribing and I will see you next time thank you [Music]
Info
Channel: SATSifaction
Views: 26,527
Rating: undefined out of 5
Keywords: python virtualenv, python virtual environment, virtualenv, ipython, jupyter kernel, adding kernel to jupyter, ipykernel tutorial, pip install ipykernel, Jupyter Notebooks virtual environment, kernelspec, python, python3, python tutorials, python tutorial, virtual environment, video tutorial, python programming, virtual environment python mac, python (programming language), computer science, engineering, packages in virtualenv, install packaged in a virtual environment, technology
Id: 8AhIs6yI6Sc
Channel Id: undefined
Length: 7min 14sec (434 seconds)
Published: Sun Oct 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.