Visual Studio Code for Python Developers Transcripts
Chapter: Managing Environments
Lecture: Handling multiple Python Versions with pyenv

Login or purchase this course to watch this video and the rest of the course contents.
0:00 When you're about to dive into a project, one of the things you might want to know is, well, which version of Python am I supposed to use?
0:07 And is it different from the other versions that I already have installed on my machine?
0:11 You might also be in a situation where you have different projects on your machine, which all require a different version of Python.
0:18 Now, it can get really tedious if you have to manage the installation and swapping between these different versions as you go from project to project.
0:26 Luckily, there's tools available that make it a lot easier for us. And we're going to take a look at PyEnv, or pyenv,
0:34 which is a free open source command line tool that makes it easy to switch between multiple versions of Python.
0:40 Now, in this video, we're going to see how to get pyenv installed on our machines. We're going to see how to work with it inside of our terminal
0:48 by installing different versions of Python and switching between them. And we'll also see how it works with Visual Studio Code
0:54 when we're trying to work with our projects. Over in VS Code, I'm going to open up the terminal.
1:00 And since we're probably going to spend most of our time in here, I'm just going to go ahead and drag it to the top
1:05 so it can take up most of our screen. Now, I'm going to type in python --version.
1:10 And as you can see, I actually don't have Python installed in my computer. So what we need to do is, why don't we go ahead and install PyEnv
1:18 and install a version of Python that I can start working with. Now, since I'm using macOS, I'm going to install PyEnv using Homebrew.
1:26 Make sure you head over to the PyEnv website so you can see the PyEnv website. And you can see the installation instructions that you're going to need
1:32 for the operating system that you're using. Now that the installation is done, I'm going to clear the terminal
1:36 and I should be able to type PyEnv on the command line. And now I should see a list of commands that we're able to execute.
1:42 If I type PyEnv versions with an S, it'll show me the different versions of Python I have set on my machine.
1:49 And right now it has an asterisk next to the system version, but I actually don't have Python on the system. So let's go ahead and install one.
1:56 If I go ahead and type PyEnv install-l, it'll show me all of the different versions of Python that I can install using this command line tool.
2:05 Now, I think one of the most current versions of Python is 3.11. So I'm going to go ahead and install that one. So I'll type Python install 3.11.3.
2:16 Now I'm just going to let it go ahead and do its thing. It's going to download Python from the internet and set it up on my machine.
2:22 Now this may take a second, so I'm going to fast forward the video a little bit so we can get to it. Now that that's installed,
2:29 I should be able to say, I'm going to start working with Python on my machine, right? But I'm still getting an error that says command not found.
2:34 What we need to do is to set the version of Python we just installed as the global version on our machine. So if I type PyEnv versions,
2:43 again, you can see the different versions of Python we have installed, and 3.1.11 is the one that we just got. If I type PyEnv global,
2:53 and I'll type in the version that we want, 3.11.3. Now if I type Python, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say,
3:04 PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
3:11 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
3:18 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
3:26 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
3:33 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
3:41 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
3:48 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
3:56 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
4:03 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
4:11 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
4:18 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
4:26 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
4:33 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
4:41 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
4:48 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
4:56 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
5:03 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
5:11 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
5:18 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
5:26 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
5:33 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
5:41 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
5:48 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
5:56 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
6:03 it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local.
6:11 So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local, it's going to say, PyEnv local. So if I type PyEnv local,
6:18 it's going to say, PyEnv local. So if I type python --version, this should say 3.11.3. But I'm still inside of my folder.
6:27 What if I went to a different folder? What if I just went to, I don't know, let's just go to the root folder. This is not a good idea,
6:33 but don't do bad things here. If I type in python --version, notice now I'm getting a different version of Python. Because PyEnv is installed,
6:42 and I'm able to set both local and global versions of the Python interpreter that I'm using. And now this becomes really handy,
6:49 as you're switching between projects, and you can have a different version of the interpreter referenced based on the folder and based on the project
6:55 that you happen to be using. Now to close out this video, why don't we take a look at some of the useful commands that you can run using PyEnv.
7:03 We saw PyEnv versions, which allows us to list all of the available versions of Python that are installed on a local machine that we can start using.
7:12 PyEnv install dash L will list all the versions of Python that we can install using this tool. PyEnv install with the version number 1,
7:19 will allow us to download and install the version of Python that we chose. And last but not least, we have two very special ones,
7:26 which are PyEnv global and local. The global one lets us set the global version of Python that's set across our entire machine. On the local one,
7:35 we'll set the context for that particular folder. So if you want to have different versions of Python referenced within a particular folder,
7:42 which represents a particular project, you can use that command to do that.


Talk Python's Mastodon Michael Kennedy's Mastodon