Introduction

Today I needed to install Pyenv again (in a Linux Mint system). I thought it was a good opportunity to take note of the steps.

Installing Pyenv

As per the instructions in the GitHub repository, I used this command for the installation:

curl https://pyenv.run | bash

After installing, I could not successfully run pyenv in the terminal. The reason was that there is one further step needed, which is explained at the end of the pyenv installation. The following code needs to be appended to .profile and .bashrc.

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

After that last step, I closed the terminal, reopened and Pyenv was working.

Updating Pyenv

To triple-check, I followed the instructions in here to ensure the correct Pyenv version.

Installing Python

I checked the versions available with the command:

pyenv install -l

Then I proceeded with the installation using:

pyenv install 3.12.5

Python got installed but I got two errors related to packages that were not installed in the os. I have below the errors:

...
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
...
...
ModuleNotFoundError: No module named '_lzma'
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
...

I solved that with the following commands:

sudo apt-get update
sudo apt-get install liblzma-dev
sudo apt-get install tk-dev

Finally, I uninstalled and reinstalled Python, and this time it installed with no warnings.

pyenv uninstall 3.12.5
pyenv install 3.12.5

Setting Global Python Version

I decided I would leave the version I just installed as global for now. I used the command:

pyenv global 3.12.5

Once this was done, inputting python in the terminal would open the REPL of the correct python version.

$ python
Python 3.12.5 (main, Aug 13 2024, 12:44:25) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>