Pyenv: Install multiple versions of Python on your system

python logo

Python has become quite a popular programming language due to its simplicity of use compared to other languages. Hence there are many applications and tools for Linux written in this language.

Many of them have not been updated to the new versions of Python due to programmer abandonment or by any other, but the application is still functional or the application requires a certain version of Python.

This can lead to a big problemThis is why we can make use of an excellent tool that will allow us to install different versions of this language on our system.

About pyenv

The tool we are going to talk about today is Pyenv is a simple, powerful, free, open source and cross-platform tool that is focused on managing multiple versions of Python on Linux systems.

Pyenv is a tool that is based on rbenv and ruby-build and that this was modified so that it could work with the Python programming language, which in a nutshell is that it is a fork to Python.

This excellent tool helps us install, manage and switch between multiple versions of Python, which is typically done to test code in multiple Python environments.

This tool can be very useful to programmers You want to test your creations written in Python in multiple environments and in different versions of Python.

With it, you will save yourself having to install and uninstall each version of Python on your systems or having to be from one computer to another with the same system but with a different version of the programming language.

Between sthe main characteristics of this tool we can highlight:

  • Be able to change the global version of Python per user.
  • Setting the local version of Python per project.
  • Management of virtual environments created by anaconda or virtualenv.
  • It allows you to override the python version with an environment variable.
  • Search for commands from multiple versions of Python and more.

How to install Pyenv on Ubuntu 18.04 and derivatives?

Si want to install this great tool, we must open a terminal with Ctrl + Alt + T and we are going to install some dependencies for the application:

sudo apt-get install -y make build-essential git libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

Now we can proceed to install Pyenv on our computers It is by downloading the tool from your space in github and we will use the script pyenv-install.

All you have to do is run the following command in your terminal to install pyenv.

curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

When executing this, we must wait for it to download and install. At the end of the installation, the installer will notify you to add Pyenv to your personal folder.

So that must add the following lines to your file ~/.bash_profile, we must open a terminal and execute:

nano ~/.bash_profile

And we add the following lines at the end of the file, here we must replace "USER" with your system username.

export PATH="/home/USER/.pyenv/bin:$PATH"

eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

We save the changes with Ctrl + O and exit nano with Ctrl + X, now we must make these changes valid by executing the following command:

source ~/.bash_profile

Pyenv is ready to use.

How to use pyenv in Ubuntu?

pyenv

Once the installation is done, we can verify that it is running and know what versions of Python we have available to use in our system.

For this we are going to open a terminal and we are going to execute:

pynev install -l

O they can also run:

pyenv install –list

This command will display all the available versions.

Now to know the one we have installed we must execute:

pyenv versions

For install any of the available versions that Pyenv showed us steps back we can execute this command:

pyenv install x.x.xx

Where we replace the x with the version of Python that we want to install on the system.

Finally, to change the version of Python we do it with:

pyenv global x.xx.x

If you want to know more about this tool you can consult the following link.


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.