Too Many Python Versions to Manage? Pyenv to the Rescue

neub9
By neub9
2 Min Read

Image by Author

Looking to experiment with the latest Python version in the morning and then tackle a legacy Python codebase during your lunch break, without disrupting your development environment? With Pyenv, you can do just that. This tutorial will walk you through setting up and using Pyenv.

To get started, the first step is to install Pyenv. If you’re on a Linux machine, you can use the following curl command to install Pyenv using the pyenv-installer:

$ curl https://pyenv.run | bash

After the installation is complete, you’ll be prompted to finish setting up your shell environment to use Pyenv. You can add the following command to your .bashrc file:

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

Once installed, you can start using Pyenv to install specific Python versions, switch between them, and remove versions you no longer need.

After installing Pyenv, you can use the pyenv install command to install specific Python versions and pyenv versions to check the list of installed versions. You can also troubleshoot any possible errors that may arise during the installation by installing the required build dependencies.

Once installed, you can set a global Python version, and also set a local Python version for specific project directories. And if you no longer need a Python version, you can uninstall it using the pyenv uninstall command.

Additionally, you can explore the pyenv-virtualenv plug-in to create and manage virtual environments.

Overall, Pyenv makes it easy to manage multiple Python versions on your system, allowing you to work on different projects with different Python version requirements.

Happy coding!

Image by Author

Bala Priya C is a developer and technical writer from India with expertise in DevOps, data science, and natural language processing. She enjoys writing, coding, and coffee! Currently, she’s working on authoring tutorials and how-to guides to share her knowledge with the developer community.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *