How to Use venv to Create Virtual Environments in Python 3 (multiple versions)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone this is tony futurist tech i'm tony and in this video i'm going to show you how to install a python virtual environment using vm venv this is a pretty straightforward tutorial there's only one thing you have to know up front here and that this will work for python version 3.3 or greater let's go ahead and get into the tutorial here and we will check our python version right off the bat here so we are working with python-version 3.8.5 and i'm going to show you in this tutorial how to use multiple versions of python to install multiple different python virtual environments so let's see where is this one located so we can do which python and that is coming from this directory on my system i do have another version of python in the user bin let's just see we have a whole bunch of python things in here so python 2.7 that won't work but we do have this version here python 3. so let's see what version that is user bin python 3-version and that is python 3.7 so we can use each one of these for an example how to do that virtual environment so let's go ahead and do that i like to put all my virtual environments inside of my home directory in a directory called env which is short for environment you can come up with any scheme that you want or you can have these scattered all over your system that's okay too anyway let's go ahead and use this version of python up here the 3.8 to create our first virtual environment and we can do that with python dash m v e n v and then the name of your environment and this is going to be like a full path so um it could be a relative path so i'm going to put the virtual environment in my m directory and then i'm going to call it my m just that's the name of it so we'll go ahead and do that and this is going to create a virtual environment using python 3.8.5 so how do we activate that we can do source and then a relative path enb mymv bin and let's just we'll tab tab complete here so there's a bin directory include directory a lib directory this was all created for us when we executed that command so inside the bin directory you have oops that's what we want actually but let's just go ahead we have our activate command that's what we want to execute but there's also pip there's also python and then python 3.8 so let's go ahead and activate the python virtual environment and you'll know that it's activated when you see this prefixed uh behind your terminal window here so we can test it out again python dash version and this because we are activated v-e-r-s version because we have activated our virtual environment we're going to be using the version of python that's installed in the virtual environment and if that doesn't make sense i'll show you here in a second so python version we're using version 3.8.5 and then if we do which python this time it's coming out of our virtual environment that we just created so anything that we do in here including pip will install all those packages inside of this virtual environment so let's let's try that so like we'll do the same thing which pip the pip should be coming out of this virtual environment and it is and we can do something like pip install pandas and that will install to this virtual environment only not on the system just that virtual environment so that'll take a couple more seconds here and until it installs and everything and we'll just quickly test it out just to demonstrate that functionality and then we will go ahead and install another virtual environment with a different version of python so let's just open our python command prompt here import pandas and should work yep there we go so we're good to go that's enough proof for me that that's working let's deactivate a virtual environment we can do that with the d activate command and now if you do which python again we are back to the system installed version of python here so let's finally go ahead and install a another version another virtual environment with another version of python so we can do that same type of thing that we did before so this time we just want to be specific about the version of python we're using so user bin python python three and again this was 3.7 um dash m v e n v and then we're going to call this we'll call it pi we'll just call it pi37 and we want to make sure that we specify where we want that to be living and that's going to be in the m directory okay so let's go ahead and make that and now let's just let's look in here in our m directory we have two different virtual environments we have the first one this is 3.8 and then 3.7 so let's activate the second virtual environment the source let's give it a relative relative path n pi 3 7 bin activate and now we have that prefix on our terminal window here we can do which python it's coming from our virtual environment and we can do python dash dash version python 3.7.3 so that should be good um for this tutorial i hope it was very valuable to you if it was please consider subscribing this video not this video to this channel i have plenty of other videos that you can watch about python so check those out and guys give it a thumbs up um i will see you in the next video
Info
Channel: Tony Teaches Tech
Views: 40,642
Rating: undefined out of 5
Keywords: python venv, python venv tutorial, python venv activate, activate venv python, python 3 create venv python3 create venv, deactivate venv, source venv bin activate exit venv, python virtual environment
Id: -TZfH7r33CQ
Channel Id: undefined
Length: 6min 5sec (365 seconds)
Published: Tue Nov 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.