Modern Python Projects Transcripts
Chapter: Python versions and packages
Lecture: Installing new Python version with pyenv

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right. Now that we have Pyenv installed, it's time to install some brand new Python version, to see a list of which Python
0:08 versions you can install. Just run pyenv install --list. You will see a huge list of available Python installations. At the top of this list,
0:21 you will see a standard cPython versions. Those are the Python versions that we will be installing and using.
0:29 You can see we still have Python 2 and Python 3 all the way, To Python 3.10 dev. But apart from that, you can also see Anaconda, Iron Python,
0:45 miniconda, pypy and so on. So, all those different types of Python versions can also be installed with pyenv. if you ever want to try,
0:55 let's say pypy. This is the easiest way, how you can install it. So, let's say I want to install the latest stable version of Python.
1:04 Let's see, which one is that? Okay, so we can use Python 3.9.0, So, let's copy it and let's run pyenv install command.
1:20 This installation is going to take a while. As you can see, pyenv is already using open ssl, and a read line that I have installed on my computer.
1:29 If you don't have those dependencies installed pyenv in full, try to download them, each time you install a new Python version.
1:37 So to speed up this process a bit, I suggest you go to the Github repo pyenv and check out how you
1:43 can install those additional dependencies. So let's do this now. If you go to the GitHub repo of pyenv and you scroll down a bit,
1:55 the installation instructions, you will see point number 5 installing Python build dependencies.
2:06 This will take you to a wiki page where you can see how you can install those dependencies, depending on your operating system.
2:14 Since I'm using a Mac, I just have to run this one command, For Ubuntu to centos fedora. You have different commands, and if you're a Windows user,
2:27 I don't think there are any additional dependence is that you have to install. At least I haven't found anything here,
2:38 So, let's go back to our terminal and it's done. As you can see, it took almost four minutes,
2:45 but at least no problems. So to see the list of available versions of Python you can run pyenv versions command.
2:54 As you can see, we have the system Python that I told you not to touch. And now we have 3.9.0 that we can use.
3:01 This Asterisk means that this is the current version we are using. So if I run Python --version, you can see I'm still using 2.7.
3:13 And if I want to switch to a different Python version, I just have to run pyenv global 3.9.0. And as you can see, this doesn't work,
3:24 which is actually great because I can show you how to troubleshoot pyenv. So, when you install a new pyenv version and you can't switch to it,
3:33 Means that you should run pyenv rehash command. This commands updates by pyenv, so it's now aware that we have this 3.9 version and
3:45 it's ready to use. And if this still doesn't work, make sure that pyenv is actually correctly set up. So, if we go back to the GitHub page,
3:57 you can see that in the Step 3, we have to add pyenv in it to our shell. In my case,
4:04 I forgot to do this And I can see this by running echo $PATH Command. You can see Pyenv is not on this list and my computer is using the default
4:14 Python version. So let's follow the instructions from GitHub. I'm using Z Shell. So I have to take this command and added to my
4:25 Z shell RC(.zshrc) file, Here I have some custom commands, so don't worry about it. And here I am adding command to initialize pyenv.
4:38 I have to restart the shell and hopefully pyenv should work correctly now. Yeah, it's working. You can see that I have a different Python version.
4:47 That's because when I was debugging this issue, I installed yet another Python version.
4:52 So you can see I have already two pyenv versions and the system Python. But now I can easily switch between those versions.
5:08 So, that's how we can easily install and switch between different Python versions.
5:11 Next, we are going to talk about three different levels at which pyenv works.


Talk Python's Mastodon Michael Kennedy's Mastodon