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