Skip to content

pyenv do as an easier alternative to PYENV_VERSION= pyenv exec #1932

Closed

Description

@native-api

Too many issues will kill our team's development velocity, drastically.
Make sure you have checked all steps below.

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

Quite often, I need to run a command against a specific installed version statelessly (i.e. without affecting the current environment).

  • The current way to do that is PYENV_VERSION=<version> pyenv exec <command>, or PYENV_VERSION=<version> <command> if the executable is a shim
  • All other ways are stateful:
    • pyenv local/global
    • pyenv shell

After seeing a very convenient and quick-to-type rvm do command for that in RVM, I just don't want to type all the above each time anymore! 😄

Activity

  1. StoneMoe commented on Oct 12, 2021

    @StoneMoe

    If you are using fish shell, and you want this feature RIGHT NOW:

    ~/.config/fish/config.fish

    # pyenvdo
    function pyenvdo
        pyenv shell $argv[1]
        $argv[2..-1]
        pyenv shell -
    end

    ~/.config/fish/completions/pyenvdo.fish (Optional for auto-complete)

    complete --command pyenvdo -d "Installed" --argument "(pyenv versions --bare)"

    now you can

    pyenvdo 3.6.10 pip list
  2. jimconner commented on Oct 25, 2021

    @jimconner

    I'm here because I was looking for a solution to the exact same problem. I've got a bunch of pip-installed commands and I'm trying to find a way to work in a directory which has a .python_version already without having to pip-install everything for that specific version of python.

    A pyenv do command sure would make life simpler for me.

    +1 for this feature request.

  3. kotokaze commented on Oct 5, 2022

    @kotokaze

    I wrote pyenv-do plugin as a patched alternative for pyenv exec. This approach would compatible with native exec command but still need hack for the completion part.

  4. 1Mark commented on May 20, 2023

    @1Mark

    pyenv exec ... -- 3.11.3 would suit the current flag better?

  5. native-api commented on May 20, 2023

    @native-api
    MemberAuthor

    I wrote pyenv-do plugin as a patched alternative for pyenv exec. This approach would compatible with native exec command but still need hack for the completion part.

    Not sure why the environment argument is optional. The entire purpose of do is to have that extra argument. If you don't need it, you have exec (or just running the command if it's a shim).

  6. mrmeszaros commented on Jul 3, 2023

    @mrmeszaros
    Contributor

    I think the idea would be able to replace exec, and not to need two commands for doing one thing.

    However, ideally I think this could be merged as an option named --env= or --with= into the exec command.

  7. macayu17 commented on Nov 14, 2026

    @macayu17
    Member

    @native-api I'd like to pick this up. I'm thinking pyenv do <version> <command> that just sets PYENV_VERSION and calls pyenv exec, with the version required. Does that work or is it better having it as an option on exec?

  8. native-api commented on Nov 14, 2026

    @native-api
    MemberAuthor

    I'm thinking pyenv do <version> <command> that just sets PYENV_VERSION and calls pyenv exec, with the version required. Does that work or is it better having it as an option on exec?

    As per the discussion above, pyenv do is a clear winner.
    IMO documenting it as equivalent/alias to PYENV_VERSION=<version> pyenv exec is enough.

  9. native-api commented on Nov 14, 2026

    @native-api
    MemberAuthor

    We can discuss adding --env or something to pyenv exec as a separate idea and see how much traction it gets.

  10. macayu17 commented on Nov 16, 2026

    @macayu17
    Member

    Thanks, I'll put up a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions