Install latest python version with pyenv

15,678

Solution 1

Try https://github.com/momo-lab/pyenv-install-latest

Installation...

git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest

Latest 2.7 build of python...

pyenv install-latest 2.7

and for python 3...

pyenv install-latest

Solution 2

The following is a little shorter than your suggested "hack" and assumes you don't want versions like 3.5.0b1.

pyenv install $(pyenv install --list | grep -v - | grep -v b | tail -1)

Solution 3

FWIW as of 2021 this issue is finally fixed (better late than never): pyenv/pyenv#1831 lets you suffix any section of version with :latest (just avoid :latest alone it yields weird results) to get the latest revision for that section e.g. right now 3:latest will install 3.11 alpha, 3.10:latest will install 3.10.0.

It's not quite perfect when dealing with non-mainline, and :latest doesn't work in every context, but it's progress.

Solution 4

Combining this with this answer, another option is:

pyenv install --list | grep --extended-regexp "^\s*[0-9][0-9.]*[0-9]\s*$" | tail -1

The regex looks for lines that start with a number ^[0-9], followed by any amount of dots and/or numbers [0-9.]*, and end with a number [0-9]$. Leading ^\s* or trailing \s*$ whitespaces may occur but don't have to.

Edit: to install:

pyenv install $(pyenv install --list | grep --extended-regexp "^\s*[0-9][0-9.]*[0-9]\s*$" | tail -1)
Share:
15,678
user137369
Author by

user137369

Updated on June 15, 2022

Comments

  • user137369
    user137369 almost 2 years

    With ruby-install, to install the latest stable ruby version, one needs only ruby-install ruby.

    However, with pyenv one seems to need to do something ridiculous like pyenv install $(pyenv install --list | sed 's/^ //' | grep '^\d' | grep --invert-match 'dev\|a\|b' | tail -1).

    Is there a better way to do this? Why do python tools seem to always make installing the latest version such an obtuse process compared to ruby (gem update vs pip list --outdated | awk '!/Could not|ignored/ { print $1 }' | xargs pip install --upgrade)? I hope I’m the one missing something, but I can never find easy solutions for this online.