Python has a lot of different versions.
Python 2 isn't really supported at all anymore, so we're
not even going to go over Python 2,
but Python 3.5, for example, is still very popular, and it
doesn't support things like an f-string.
So let's just go into our IPython here and we could do 'name
= "Kalob", and as an f-string, we could say "Hello
". And it says, "Hello Kalob".
And it just happens to be that Python 3.5 does not support
that. So what if you're using a specific version of Python
on a specific project?
Let's say you just get hired at a new company and you run
'python -V', and you're using Python 3.7,
but they're using Python 3.8, and they're using a feature
that's only available in Python 3.8 called the 'walrus
operator'. Well, you can no longer use Python 3.7.
You need to upgrade, but you don't necessarily always want
to just upgrade to 3.8.
You might also want to keep 3.7 around because you have other
projects that still use Python 3.7.
Now, for the most part, that's actually not really gonna
be a problem, just because Python is for the most part quite
reverse compatible.
Meaning if you have Python 3.8 installed and your projects
are using Python 3.7, chances are your projects using 3.7
will probably work still.
But there is the occasional time where that is not true.
So given this hypothetical situation where you just get hired
at a new company and you need to use a different version
of Python, how do you get it?
Well, there's a thing called 'pyenv', and if we open up our browser,
and I think it's just 'github.com/pyenv/pyenv', I hope that's correct.
Yep, looks like it. 'pyenv' is basically 'py environment', and that
allows you to have different versions of Python.
And let's read the description.
'pyenv lets you easily switch between multiple versions of
Python. It's simple, unobtrusive, and follows the Unix tradition
of single-purpose tools that do one thing
well'. I would say that's true.
I use it quite a bit,
I really like it. Table of contents,
let's go down to 'Installation'.
So if you are on a Mac, you can consider installing it with
Homebrew, and let's click on that.
And it is simple as 'brew.
update, brew install pyenv'.
If you're on a Mac, and you don't have 'brew', you might want
to get 'Homebrew'. It is a nice little package manager.
It's like 'pip', but for your macOS. If you're on Windows
you're gonna have to use 'pyenv-win' because Windows is a little bit different.
It's not really Unix based at all, whereas Mac actually has
a little bit of Unix inner workings inside of it still.
So if you're on Windows, definitely check out 'github.com/
pyenv-win/pyenv-win'.
And so if you want, you can go ahead and get that installed.
Now before you do that,
if you have Anaconda installed, 'anaconda.com',
if you have this installed, you're probably going to run
into some problems.
Anaconda comes with its own distribution of Python, which
can actually compete or conflict with 'pyenv' a little bit.
I've actually noticed that in my own experience.
So preferably if you're going to use one, just stick with one of these.
Now, once you have that installed, if you wanted to, you
could just go straight to your command line here.
Let's clear this out, and we can do 'pyenv',
let's just type 'pyenv',
let's see what happens. 'pyenv', 'some useful pyenv
commands are:' - commands, local, global, shell, install, uninstall,
rehash, version, versions, which and whence. We really only need
a few of these. Let's do 'pyenv versions', because this one's going to list all
the Python versions that are available on 'pyenv'.
These are the ones that I have on my computer.
So I currently have Python 3.5.7, 3.6.0, 3.7.2, and 3.8.0
So if I do 'python -V', this is the version I'm using, Python 3.7.2,
but I can now change that very easily with 'pyenv',
and I'm going to change this across my entire system
right now. 'pyenv global 3.5.7',
and let's do 'python'.
let's spell 'python' correctly, though, and look at that.
I'm using a different version of Python now.
And if you want to see the current version, you can literally
just type 'python version', and it will tell you in here, not
'python version', 'pyenv version',
and it tells you which one you're using.
And let's go back to, let's not go back,
let's change our version to Python 3.8.
So I'm going to do 'pyenv global 3.8.0',
that's because I have that installed already.
'pyenv versions' tells me I have it set. Now
what happens if you want to install a new version?
We just have to find out the version that you want, and then you can
do 'pyenv install', and then the version name.
Let's see what happens here.
It'd be really great if it gave us all the version names,
but you could effectively do 'pyenv install 3.8.0', and it will
install it for you, and then you can use it.
I'm actually going to go back to 3.7, because that's what
a lot of my projects right now are using, 'pyenv global 3.7.2',
'pyenv version', and I'm back on 3.7.2.
Once again, there is a little bit of a conflict here.
So if you are using Anaconda, chances are you're going to want
to continue to use Anaconda,
otherwise you're going to run into some pathing issues,
and I've noticed that those issues are not the most straightforward
problem to solve.
But if you aren't using Anaconda, 'pyenv' is definitely a good way to go.