Manage multiple python versions like a Pro
There are several versions of Python with different packages depending on different versions. Most of us programmers don’t have just one project to work on…
The ability to have multiple python versions for different directories would make your lives much easier. Let me show you how to manage multiple python versions like a pro.
Installpyenv
Followthislink to getpyenvfor your system.
Once installed, you’re all set to install multiple python versions as follows.
Install multiple python versions
Get the list of all the available versions:
pyenv install --list
ORpyenv install -l
This will show all the available python versions inpyenv. This list might be cumbersome to look at, so instead you could grep versions from the list. For example, if you want to install python 3.7.x, you can do:
pyenv install -l | grep 3.7
(on Unix systems)
pyenv install -l | findstr "3.7"
(on Windows CMD)
Now, you can install multiple different python versions from the list (yes, as many as you want!). As an example, let’s install python versions 3.7.11 and 3.10.2
pyenv install 3.7.11
pyenv install 3.10.2
Setting global default python version
To set the default global python version for your system, you can do:
pyenv global 3.7.11
Note: You can runpyenv global
to see the currently set global python version.
Setting local python versions for directories
For each of your project directories, now you can change the local python interpreter version as follows:
cd your_project_directory
pyenv local 3.10.2
This will set the local python version in “your_project_directory” to 3.10.2 while your system still uses python 3.7.11 !
Conclusion
Congratulations
Now you are a pro in managing multiple python versions!