Is `pyenv activate` supposed to be usable in noninteractive shells?
In https://github.com/pyenv/pyenv/issues/1914, a user was getting the Failed to activate virtualenv. Perhaps pyenv-virtualenv has not been loaded into your shell properly. message when trying to pyenv activate in a noninteractive shell.
OS: Debian Buster 10 (AWS / EC2) Pyenv: 2.0 Pyenv-virtualenv: 1.1.5 Debug trace: https://github.com/pyenv/pyenv/issues/1914#issuecomment-848977120
Is pyenv activate supposed to be usable in this scenario?
- If yes, Pyenv-virtualenv's -- and also Pyenv's -- documentation needs to be rewritten to install shell functions into both interactive and non-interactive shells -- including the case when the login shell and the running shell are different shells.
- I'm not sure if this is a good idea: it's going to be disruptive, requiring stuff like setting
BASH_ENVand creating a new script file.
- I'm not sure if this is a good idea: it's going to be disruptive, requiring stuff like setting
- If no, the error message needs to be fixed to not read like a configuration error but instead instruct the user to
sourcethe activation script directly or something.
I find this rather interesting. I'm trying to set up a Docker image where pyenv is available and usable (for both production and development purposes), and it would be interesting to know what the maintainers have to say here.
Well, I'm the (main active) maintainer now.
From what I can see in the codebase, Pyenv has never loaded, or it's documentation suggested to load by default, shell integration into noninteractive shells. Probably because that's prone to breaking scripts.
So if you need commands like activate that need shell integration, in noninteractive shells, you need to run the necessary init commands manually or change shell startup files accordingly.