Creating a Virtual Environment within a Jupyter Notebook!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video we'll learn how to create a virtual environment within a jupiter notebook let's start first by reviewing what a python virtual environment is and it is a way to create a virtual installation of python inside a project directory users can then install and manage python packages for each project this allows users to be able to install packages and modify their python environment without breaking packages installed in other environments let's go over a use case for this dependency issue let's say that we want to review a project that uses tensorflow 2.10.0 we have all these dependencies that are required in order to run tensorflow including numpy version 1.2.3 however in the environment that we're working in we have numpy 1.0.0 this becomes an issue because if we have another package that relies on numpy 1.0.0 and we override it with the newer numpy then that will break that package dependency which is why we would want to set up a virtual environment in order to review this project we also have an issue of package bloat if in a certain environment whether we're just running it locally or within another virtual environment we keep downloading and installing more and more packages then we'll take up a lot of memory for example tensorflow takes up a lot of memory 1.26 gigabytes the other packages may not they only take a few megabytes or kilobytes but if we install more and more packages this will bloat our available space and potentially cause issues for us and we may never use these packages again which is again why we'd want to set up a virtual environment that we could delete later once we're done reviewing the project now that we know why we would create a virtual environment let's stand one up i am going to exit out of our jupiter notebook within our downloads folder it will create the environment when you install python there's a built-in virtual environment manager called venv that we will use i'm going to type python-m then called the v-e-n-v package then i am going to name our environment test let's run this and we've set up our environment within the downloads folder let's bring it up and we could go inside and we could see that we have some scripts a library we can take a look at the site packages and we can see that we have pip within our virtual environment which will help us install some things that we need if we go back out and go into scripts we'll have to activate our virtual environment and what i'm going to do is i'm going to copy the path go back to our command prompt and change directory into the scripts folder and i am going to activate it i'm going to type in activate tab and then hit enter and we can see that we are in our environment we can see the name of the environment test within parentheses what i have to do is i need to install a few things what i'll do first is i'm going to install tensorflow so i'm going to call pip install tensorflow next we need to install ipi kernel this time i'll go pip install i pi kernel and if we go back to our virtual environment we can go inside the library and site packages search for tensorflow and we can see that we were able to download tensorflow and all the necessary packages now that we have it installed what we need to do next is we need to create a kernel the way that we'll do this is we're going to call python dash m and we're going to call ipi kernel then we need to install and we need to do dash dash user and then finally the name of our kernel and i am going to call the kernel test and we have the full line here let's run this and now we have it added into our kernel list i am going to deactivate our current environment what we also need to do is sometimes this doesn't completely deactivate it so i'm going to close out of this command prompt and open up a new one and i am going to change directories back to our downloads folder where we have our notebook and i am going to open up our notebook by calling python-m notebook and here we have our notebook if we take a look at the kernels we can see that we can change kernels now we have the two options python3 this is our local environment and we also have our virtual environment if we scroll down we can see that we can try to import tensorflow and when we try to do that in our local environment we're unable to because we installed it in our virtual environment not our local environment what we need to do is go back to kernel and we need to change the kernel to test and once the kernel started and it's ready we'll try to import it and we can see that we were able to import tensorflow into our virtual environment and we have it set up within jupyter what we can finally do is we can uninstall our environment and i am going to do this within our command prompt again if we go back out i am going to close out of jupyter and i am going to say jupyter kernel spec uninstall test and this uninstalls our test environment we need to confirm yes hit enter and it is now removed and we can go back and we can delete our environment once we are done reviewing whatever we need to review with tensorflow thanks everybody for watching i hope that this video was helpful i included references that i used to put this together if you like the video feel free to like and subscribe you can also connect with me on linkedin twitter github and odyssey thanks again and happy coding everyone
Info
Channel: Adrian Dolinay
Views: 16,738
Rating: undefined out of 5
Keywords: Creating a Virtual Environment within a Jupyter Notebook!, python virtual environment, virtual environment python, how to create a virtual environment in python, virtual environment, jupyter virtual environment, ipython virtual environment, vm, python vm, jupyter vm, virtual env, venv, python venv, venv python, install packages python, python install package, package dependencies python, virtual environments, Python Virtual Environments, package dependency management
Id: QAoVN3Omb9Q
Channel Id: undefined
Length: 6min 6sec (366 seconds)
Published: Sat Sep 17 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.