Skip to content

The auto-resolution of latest versions feature doesn't work with python- prefixes (eg python-3.12) #3054

@edmorley

Description

@edmorley

Summary

pyenv works fine when an explicit python- prefix is added to the Python version when full versions are specified (for example python-3.12.6), however, fails to find a matching Python version if the "auto-resolve latest version" feature is used with a python- prefix (such as python-3.12).

ie:

  • Works: 3.12, 3.12.6, python-3.12.6
  • Doesn't work: python-3.12

This appears to be due to the python- prefix removal here only covering the exact match case, and not the pyenv-latest code-path:

for version in ${PYENV_VERSION}; do
if version_exists "$version" || [ "$version" = "system" ]; then
versions=("${versions[@]}" "${version}")
elif version_exists "${version#python-}"; then
versions=("${versions[@]}" "${version#python-}")
elif resolved_version="$(pyenv-latest -b "$version")"; then
versions=("${versions[@]}" "${resolved_version}")
else
echo "pyenv: version \`$version' is not installed (set by $(pyenv-version-origin))" >&2
any_not_installed=1
fi
done

I will open a PR for this.

Prerequisite

  • Make sure your problem is not listed in the common build problems.
  • Make sure no duplicated issue has already been reported in the pyenv issues. You should look for closed issues, too.
  • Make sure you are not asking us to help solving your specific issue.
    • GitHub issues is opened mainly for development purposes. If you want to ask someone to help solving your problem, go to some community site like Gitter, StackOverflow, etc.
  • Make sure your problem is not derived from packaging (e.g. Homebrew).
    • Please refer to the package documentation for the installation issues, etc.
  • Make sure your problem is not derived from plugins.
    • This repository is maintaining pyenv and the default python-build plugin only. Please refrain from reporting issues of other plugins here.

Description

  • Platform information (e.g. Ubuntu Linux 16.04): macOS 14.6.1
  • OS architecture (e.g. amd64): arm64
  • pyenv version: 2.4.12
  • Python version: 3.12.6
  • C Compiler information (e.g. gcc 7.3): N/A
  • Please attach the debug trace of the failing command as a gist:
    • Run env PYENV_DEBUG=1 <faulty command> 2>&1 | tee trace.log and attach trace.log. E.g. if you have a problem with installing Python, run env PYENV_DEBUG=1 pyenv install -v <version> 2>&1 | tee trace.log (note the -v option to pyenv install).
  1. pyenv install 3.12.6
  2. mkdir pyenv-test && cd $_
  3. echo 'python-3.12' > .python-version
  4. pyenv versions

Expected

$ pyenv versions
  system
* 3.12.6 (set by /Users/emorley/src/pyenv-test/.python-version)

ie: The same as if I had instead saved either 3.12 or python-3.12.6 into the .python-version file (both of which work fine, unlike python-3.12).

Actual

$ pyenv versions
pyenv: version `python-3.12' is not installed (set by /Users/emorley/src/pyenv-test/.python-version)
  system
  3.12.6

Trace: trace.log

Though as mentioned above, the cause seems clear and I'm happy to open a PR for this :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions