Manage Multiple Python Versions with PyEnv

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys welcome back in this video today we're going to learn how to manage and switch between multiple different python versions so let us get right into it it's not a g it's AED all right so we're going to learn how to manage multiple different python versions on our system and how to switch between them easily and the tool that we're going to use to do that is called py enf so this here is the pyen get up page it's quite simple to install you can just follow the instructions down below here in the installation section on Mac you use Homebrew on Windows you follow these instructions down here and on Linux in my case here on pop OS you just have to run this curl command so just curl hdps Colony in. run pipe bash and this will automatically install pyin on your system now once you have pyin on your system you can just use it in the command line to switch between Python versions to install new python versions without having any conflicts in the operating Sy system so all you have to do here is you have to say pend and then uh one of the commands that this tool offers for example versions to list the versions that you already have installed on your system in my case here I have three versions um the system version which is I think 3.10 so this is just the default python version that you had before pyen and then I also have 3.7 3.12 here uh 3.12 being the latest version and 3.7 just uh an older version and you can just go ahead now in your case you will probably only have system if you run this for the first time which is your default python that you're using all the time so uh what you get when you just run Python 3 in my case as I said 3.10 um and you can now go ahead and install new versions by just saying pyan install and then a version number so for example maybe you have an outdated codebase that only runs on python 3.6 you can just say Pym install python 3.6 and you can even specify an exact version 3.6 something uh if you just go with 3.6 it will take the latest release so in this case I think 3.6.5 and uh there you go so it downloads everything it configures everything and once it's done you have a new python version on your system you of course have to select it in order to be able to use it uh so you have to say okay at least for this project this is the python version I want to use or you can even use it globally so whenever you use Python this is the version that you use so we're going to talk about this here in a second now while this is installing I want to mention one thing that I encountered here on Linux I don't know if this is relevant for Windows or Mac but in my case when I installed a new python version for the first time using pyen for some reason it had some problems with TK inter that I had to resolve so what I had to do in order to be able to fully install a new python version is I had to do pseudo apt update and then I had to do pseudo apt install Dy tk- def so uh for TK enter basically because I had some problem with TK enter um because my system didn't have the developer tools for TK enter for some reason even though it worked without pan it didn't work here in the installation so this is something I had to do now as you can see here python 3.6 is installed right now if I check the versions again I have a new python version here and I can now go ahead and switch to this version globally all I have to do for that is I have to say p Global and I can choose a version so 3. 6.15 and then if I list this you can see now the risk is here on this line meaning that now the code I'm using now the python version I'm using is 3.6.5 and of course I can switch back to uh to something else 3.12 for example then I would get 3.12 here and of course if I want to switch back to the system I just say py global system and then I have my 3.10 default here now let's see what this looks like let's go into my usual working directory here and let's create two projects project one and project 2 and in Project one now we're going to create a new file we're going to call this uh let's call this main.py maybe let me zoom in a little bit so you guys can see it better uh and here we're just going to use some very basic code we're going to define a function classif y number it's going to be a very useless function doesn't really do anything interesting but we're going to use a structure that is not uh that was not included with um earlier versions of python I don't know when it was introduced maybe 3.10 or something but it's the match case structure so I can say match n which is the parameter then I can say the case that n is zero in this case I want to print just a word zero and then I have case one in this case I want want to print one and then I want to have uh case two or actually let's return to string let's say return zero return one return uh two and then we have the case underscore which is the default and we're going to return the string other so a very simple structure here and I can of course call this function so I can say print classify number and then uh two for example and of course right now I think I'm using the system version 3.10 I think they should already support this so where is my P in versions command yeah I'm using 3.10 so if I now say Python 3 main py I should just get two now what I can do is now I can go back I can copy this um project one main py file I can copy to project two then I have the same file there and first of all what I can do is I can set my Global version to an older version so I can say pend Global and then 3.7 uh now again when I run the version command you can see this is the one that I'm using and now if I go into project one uh and I run this Python 3 main.py you can see invalid syntax what is match I don't know it so doesn't work now the problem is maybe I don't want to use 3.7 on my system everywhere I want to use it for this particular project because it has an outdated code base in this case of course not because match is uh something that requires a newer version but let's say in one project I want to use 3.7 in another one I want to use the system version 3.10 what I can do is I can use the pyen global uh sorry pin local command so first let me go back to pen global system to use my default everywhere and in this particular project I want to use um a different version so or actually let's go in this one I'm I'm going to use 3.10 but in the other one so let me show you here this works again in the other one I want to use uh an older version so I want to say p and now local now okay I'm not blocking this I want to just check if I'm blocking this with my camera P local 3.7 and now you will see if I run this here Python 3 main py it will tell me that this is a syntax error but if I go into project one and I run the same file it's going to it's going to just return two and how this works is that now in Project 2 I have a file called python version It's a hidden file here and this python version file specifies which one I'm using so this is as simple as it gets now the interesting thing here or the important thing to mention is that this only uh affects the terminal if I change the version here it doesn't change in neovim it doesn't change in py charm I have to do it manually so if you want to do this in py charm what you have to do is you have to um to configure the versions down below now let me move my move my camera so that you can see this better uh down here I can choose my python version and here you can see I have 3.12 3.10 and 3.7 but I had to add them manually so you go to add new interpreter here add local interpreter and then you can just go to uh virtual n environment you can go to existing or actually uh yeah I think this was the right path and what you need to do now is you need to go to at least on Linux to home username and then to pyin this one here then you want to go to versions then you want to go to the version you want to add then to the bin directory and here to the python executable so this is how you do that and now you can see I also have python 3.6 so this is how you add this to py charm and you can also do something similar oh now I'm moving the whole thing this is not planned you can also do something similar uh for other IDs so yeah this is how you manage multiple different python versions how you switch back and forth between them easily uh using pyin so that's it for today's video I hope you enjoyed it and I hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you on the next video and bye
Info
Channel: NeuralNine
Views: 14,718
Rating: undefined out of 5
Keywords: python, multiple python installations, multiple python versions, pyenv, python multiple versions, switch Python versions, switch python installations
Id: 3my06DUnApM
Channel Id: undefined
Length: 9min 54sec (594 seconds)
Published: Mon Oct 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.