Using Pyenv to Manage Different Python Versions
/ 2 min read
When working with different projects it is common to have different versions of the same programming language and dependencies for each one of them, so if we had a single installation or global version, this could give constant conflict between different projects.
To fix that we can use tools like pyenv
and virtual environments
. What these tools do is to isolate different versions of python and different installations (environments) of each of these versions.
Pyenv allows us to have different versions globally, locally, or even for the current shell.
Installing Pyenv
To learn more about the installation process we can follow the instructions in its repository.
In general, we can use its installation script:
Configure shell environment for Pyenv
After installation there is an additional step that is supposed to be done automatically, but in my case I have found that sometimes I have to do it mannually. It is really simple: when it is done installing, you have to configure it for the SHELL you are using.
For ZSH, just type each one of these lines (or manually add the quotes inside your ~/.zshrc
):
You can see the configuration for the other shells in the README of its own repository. And don’t forget to close and open the terminal to reload the configuration file or update it with source
!
Common Pyenv Uses
We can see all available commands with pyenv --help
or pyenv
.
- See the available versions to install:
- Download and install a specific version:
- Select a version as global, local directory (perfect for when working with microservices with different versions), or for the current shell:
Aditionally, to check the version of Python being used and the location: