[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:pyenv shell is not working on Windows git bash #539

Open
g0di opened this issue Jul 25, 2023 · 3 comments
Open

bug:pyenv shell is not working on Windows git bash #539

g0di opened this issue Jul 25, 2023 · 3 comments

Comments

@g0di
Copy link
g0di commented Jul 25, 2023

Hello,

I'm using pyenv-win on my Windows computer successfully through PowerShell. However, the pyenv shell command is not working when I'm using it on a Git bash terminal. It does not output any error but it does not set the PYENV_VERSION environment variable and pyenv versions is not showing that the right Python version has been chosen.

Following is the output I've got from pyenv

$ pyenv versions
* 3.10.11 (C:\Users\TBEBGOD\.pyenv\pyenv-win\version)
  3.11.4
  3.8.10
$ pyenv shell 3.8.10
$ pyenv versions
* 3.10.11 (C:\Users\TBEBGOD\.pyenv\pyenv-win\version)
  3.11.4
  3.8.10
$ python -V
Python 3.10.11

To Reproduce

Steps to reproduce the behavior:

I'm assuming pyenv-win is already installed

  1. Install Git for Windows v2.34.1 (https://git-scm.com/download/win I'm not sure you need that exact version actually)
  2. Install two python versions pyenv install 3.11.4 pyenv install 3.8.10
  3. Run pyenv global 3.11.4
  4. Open a git bash terminal then type pyenv shell 3.8.10
  5. Run pyenv versions and eventually python -V

Expected behavior
I'm expecting pyenv versions to indicates that the version 3.8.10 is actually set and python -V should output Python 3.8.10

Desktop

  • OS: Windows 10 Enterprise
  • Tools used: Git for windows (git bash)
  • Version: 3.1.1

Additional context
I've actually tried to export the PYENV_VERSION environment variable by myself to test and it looks like it is properly working this way

$ export PYENV_VERSION=3.8.10
$ pyenv versions
  3.10.11
  3.11.4
* 3.8.10 (set by %PYENV_VERSION%)
$ python -V
Python 3.8.10

Thank you!

@rhenescu
Copy link

@g0di, add this to your ~/.bashrc and restart Git Bash:

pyenv() {
    command pyenv "$@" || return $?
    if [ "${1-}" = 'shell' ]; then
        if [ "${2-}" = '--unset' ]; then
            unset PYENV_VERSION
        else
            shift && export PYENV_VERSION="$*"
        fi
    fi
}

What happens: if the pyenv shell ... command finishes successfully, the arguments are reused to unset or export the PYENV_VERSION variable, depending on what was requested.

pyenv comes with the init command that takes care of this, after adding eval "$(pyenv init -)" to ~/.bashrc. Maybe the proper solution would be to port it to pyenv-win?

@g0di
Copy link
Author
g0di commented Sep 5, 2023

Sorry, for late reply. I gave it a try and worked like a charm. This is a nice workaround for me at the moment but as you mentioned this might be handled by pyenv-win itself. Maybe a first step could be to at least document this somewhere.

Thanks for help ;)

PS: Not sure if I should close the issue or not

@m0rphed
Copy link
m0rphed commented Oct 1, 2023

Same issue with Powershell 7.3.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants