How to Install and Run Multiple Python Versions on Windows 10/11 | pyenv & virtualenv Setup Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you want to install different python versions under windows because you work on different python projects or you just want to check out the latest release candidate of the next python version in this video i'm going to show you how to do this using pyenv together with virtual environments and how to use those two within visual studio code welcome i'm cons i got a master's in computer science and currently work as a graduate research assistant and work with python on a daily basis which makes pion to one of my most important tools using and installing different python version under windows is actually pretty easy using pion pionf is a command line tool which allows you to seamlessly switch between different python versions and also enables you to set dedicated versions for specific folders and projects together with virtual environments pyeonft is one of the most important tools for everyone who uses python on a regular basis so without further ado let's jump into windows and set up payment virtual environments and visual studio code to install pion we first have to download it from its github page which is pioneer minus win pine minus win you can find the link for that down below in the description we go to code and then we're just going to download the zip archive then we head over into our downloads folder we right click on it and click on extract all and when the extraction has finished we head into our powershell and create a folder for pyenv and we're going to create a folder.pint in our user directory for that we enter mkdir dollar home which points to our user directory slash dot pyen this created the dot pint directory in our user directory now we're going to head over into a user directory which we can find under c users or user name and in here we find the dot pi in directory we just created in the powershell now we go into the pi and win master directory we just extracted from the zika zip archive and we copy over pi and minus win and the dot version file into the dot pyth directory just created with this step the installation of pinef is technically done however we have to set up the command line in order to recognize the payent command for that we head over to my website where you can find all the commands you now have to insert into the powershell to make pine work you can find a link to my website down below in the description now that we have installed python in the dot pine directory we have to set two environment variables that point to that directory we're just going to copy those over here those are just variables containing the the path to my home directory and the dot pyth directory in it copy that and insert that into our powershell and click on enter after we have done that we now have to add pi inf to the path variable such that the pi and command is visible for the shell we are using and we can use the pi if command later on for that we are going to copy this command over here which extends the path variable with the pyenv bin folder we copy that and insert that into the powershell as well and click on enter now we have to close our current powershell and enable the execution of scripts for that we need a powershell with administrator permissions whether we close first this powershell then we go under windows type powershell and we right click on it and run at administrator we allow that we want to run it as administrator and the next thing we have to do is to enter the execution policy so we going to enter set execution policy unrestricted we just copy that as well enter that here and press enter and now we want to press a which enables us to run scripts on the whole system and not just certain scripts so capital a and enter and now we can close this powershell with administrator permissions again and open a normal powershell and in this normal powershell we enter pyen and windows will respond with a warning because we haven't given pie in the correct permissions to execute we can click on run once but we have to do this all the time if we want to run pyenf to circumvent that we can enter another command which unblocks our file we're just going to copy that from here unblock home dot pine pine win bin pi and ps1 that is the script that is actually called when we enter the pi and command into the power shell with that entered pine is now unblocked and when we enter pie in once again we don't see a warning this concludes the installation of pyent and we can now move on on how to use pyenv and don't forget to give this video a like it helps me out a lot with pine successfully running on our system now we can start using it and the first command we're going to use is the pion install command to list all the versions we can install through pi inf we enter pyen install minus l which lists all available versions of python we can install with pyenv and there's a lot of them but we want to stick to the c python implementation and the most recent version we can install for the c python implementation is 3.9.6 and to install that we just enter pyen install 3.9.6 press on enter and wait until pionf installs this version of python with the installation of this python version being finished we can check which versions are actually installed with pyenv and for that we are going to enter the command pyen versions that lists all the versions that are currently installed and we only installed the version 3.9.6 so this is the only version that has been listed here now we want to use this version in this shell for that i'm going to use pi end shell and enter 3.9 3.9.6 and this activates this python version just for this shell session if we now enter python minus v we can see that we now use python version 3.9.6 and in this directory i already have a short python script which is just a hello world which prints out the python version we can run that as well we enter pi python hello pi and we see it says hello i'm python version 3.9.6 setting the python version every time we open a new shell is very tedious so for that we are going to use high end global 3.9.6 and now when we open a new powershell and enter python minus v we can see that per default pi is now using python version 3.9.6 however i would like to check out the latest release candidate of the next python version 3.10 for that i'm looking once again into pi and install minus l and down here we can see the latest beta which is 3.10.0b3 and we're going to install that as well pi n install 310 0b free and press enter and wait until it is installed i don't want to use this release candidate of python on my whole system i just want to use it in my python test project and for that i'm going to use the pi n local command and enter 3.10.0b3 and this will create a dot python version file when we enter ls to list all the files in here we see there is the dot python minus version file and that has a string in it that tells pay and which version we would like to use in this directory so when we now run our hello python with python hello pi we can see it doesn't use 3.9.6 anymore but it uses 3.10 in this quick overview of the different pionf commands we've seen the install command versions shell global and local however there are a lot more commands which you can check out over on the pi hand github repository now i want to use a virtual environment in my test project which allows me to install modules just for this project in a specific directory for that we are going to use the python virtual environments which we can create with python minus m went dot vent and this will create a new directory called dot vent which will include all the modules we are going to install together with the python interpreter we have just copied over from pyenv if we have a quick look at the dot venif directory ls then and go into the scripts directory we can see there is an activate shell script we have to run when we want to activate this virtual environment and we can also see a python exe and a pip exe which will be run when we have activated the virtual environment in order to install or run our commands to activate our virtual environment we're going to enter dot vent scripts activate and press enter and then we see this dot vent appearing in front of our prompt that means we're now using the virtual environment and to check that we are actually using the virtual environment we are going to run get command dot pip and that points to the directory where the pip command lies and that is for us pi and test vent scripts so the virtual environment is actually working and as a last step i would like to use this virtual environment in visual studio code such that we can use the new release candidate of python together with our modules we just installed for this project so we're going to start code with code dot in our python test directory which will open a new a new visual studio code window and in here we can see we have the hello pi i just run before but visual studio's code doesn't know which interpreter we should use to fix that we're going to open the command palette with ctrl shift p and enter settings json and we going to open the workspace settings json this opens a empty json file and we will add one thing to it which is python terminal activate environment and we set that to true we save our current modifications on the settings json close the settings json then close visual studio code and we're going to open visual studio code once again and now our virtual environment is actually activated and we are using the python version 3.10.0 b3 and to run our script with this environment we have to add a launch json for that we go on the tab over here which is run and debug we're going to create a launch json file click on module and the name of our module is hello it's the file name just without the dot pi we close that and we go to run run without debugging and a new terminal pops up down here and in here we can see that it actually activates our virtual environment and then runs our hello pi script and actually prints out the correct version we have set through pi in this directory in our virtual environment i hope you enjoyed this video let me know in the comments if it was helpful for you don't forget that you can find all the comments i've been using in this video on my website together with a complete documentation on how to set up pi on different systems together with virtual environments and visual studio code you can find a link to my website down below in the description don't forget to give this video a like and if you want to catch up with me consider joining our lovely discord community last but not least big shout out to my patreon subscribers for their support and i hope that i see you in my next video have a fantastic day and bye bye
Info
Channel: k0nze
Views: 78,366
Rating: undefined out of 5
Keywords: python tutorial, learn python, pyenv, python, windows 10, python 3, python programming, python3, windows python, virtual environments, install python, virtualenv, install pyenv windows, venv, python virtual environment, python virtual environments, pipenv, install python windows, vscode, visual studio code, vs code, pyenv-win, k0nze, k0nze builds, Konze, python for everyone, python for everybody, tutorial, windows 11
Id: HTx18uyyHw8
Channel Id: undefined
Length: 12min 38sec (758 seconds)
Published: Sat Sep 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.