You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I updated my Homebrew install and I'm now getting an info message displayed whenever I'm changing into directories that have a .python-version file in them (I'm guessing? I'm not entirely sure on what triggers the behaviour).
It says: pyenv-virtualenv: prompt changing will be removed from future release. configure export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.`
but it's not really clear to me from that message how the prompt will change in the future and how that variable is supposed to work, i.e. what its expected behaviour is.
I added the var to my shell file just to try it out, and the resulting prompt is definitely not what I want, as it seems to get stuck in a mode where it always displays the currently activated virtualenv, regardless of where I am in my file system.
Re: what's going to change:
Will only the active/deactive messages disappear? Or both that and the prompt prefix that displays the virtualenv's name, like so (myvirtualenv) mymachine:~$?
And a general question, not directly related to this issue: are you accepting PRs for improving documentation? Because I'd really like to add a bit of info to this repo's README that would've saved me lots of time trying to figure out a particular problem I had.
Reacted by Art Nitipon Suratwisit, Alex Rothberg, Josh Winn, mairan, José María, snoop2head, Jake Robb, NAKATA Keisuke, Jonas Sander, Tal Weiss and 11 more
In pyenv-virtualenv prior to v20151222, there were some known issues related to management of $PATH and shell's prompt (#51, #69, #80).
To solve all those issues intrinsically, pyenv-virtualenv stopped using activate script generated by virtualenv, venv and conda env (#104). The virtual environments will be pick up via shims just like other ordinary versions in pyenv (e.g. 2.7.11, 3.5.1, etc.). Because these virtual environments are just a pyenv version now, I don't like to do something special for them as much as possible. I added that deprecation warning and I will remove the prompt changing feature in future releases (actually, the feature has already been removed for fish shell since it had known problem).
Now you can see what virtual environment (or a version) is activated from the output of pyenv versions, like other non-virtual versions in pyenv. Any users can configure their shell to show the name of activated virtualenv in their prompt like before, but pyenv-virtualenv will stop doing it by default in future release.
Any contributions are always welcomed. We need more hands and eyes to improve things, especially for documentation since I am pretty bad at documentation 😛
Reacted by Charana, Arno Veenstra, mobarzanek, dhivyar76, Quang Nguyen, Nahuel Ambrosini, Robin De Schepper and Jacek Laskowski
Reacted by Noel da Costa, Nejdet Çağdaş Yücesoy, mairan, Marco Martinelli, 编程悟道, Hermes Martinez, Yevgnen, Илья Лисин, Guy Arad, ppawlak and 26 more
So, you won't remove the code for changing the prompt entirely (that's how the message read to me!), but the prompt change won't be the default anymore and users will have to (re)enable it via their shell (with the PYENV_VIRTUALENV_DISABLE_PROMPTvariable)?
Is that it? And will that affect both the 'activate/deactivate' messages and the display of the virtualenv's name? (Meaning: does the variable cover both, or is it possible to only get the name displayed and not the activate/deactivate messages?)
Regarding the documentation: yeah, I'd especially like for it (any documentation, really!) to be as beginner-friendly as possible. (: So, not leaving out any info that might be helpful for people not (so) familiar with certain tools, or the lingo that comes with them.
I'd really love to see more programming beginners use Homebrew & pyenv (or chruby etc.) from the beginning as I believe it's generally a good idea not to mess with one's Mac system too much. But, for beginners, info on additional tools and how to use them can be quite overwhelming (and missing 'helper' messages can make navigation/usage of tools more difficult). So if I'm struggling with any of this, it must be n times harder for total beginners! And I'm afraid they're then more likely to just not go through all the trouble of trying to figure out how to do things (better).
Anyway, cool, I'll change that one bit I was looking to change soon, and submit a PR!
Oh, so are you planning to remove it altogether? That would be a pity. ): It's a really, really useful feature to have.
Btw. I thought about the issue some more, trying to figure out why I found the current instructions so confusing. I think it's because the variable says 'disable' for a function which will be disabled by default anyway!
People will have to 'disable' something that's already disabled, when really, they want to turn on something that's turned off by default. I.e. wouldn't it make more sense to name it PYENV_VIRTUALENV_ENABLE_PROMPT and have people set it to 0 in their shell config if they want to (re)enable the prompt?
Reacted by Sasmito Adibowo, saraatclover, Brent Payne, Madhu Bhargav, Fabian Flechtmann, Noel da Costa, duckbill, Guy Arad, Bruno Duyé, Norbert Varzariu and 26 more
I guess the PYENV_VIRTUALENV_DISABLE_PROMPT variable is just a temporary solution to let you test how it will be once the feature is removed. It will probably go away together with the feature.
Anyways, I also had a little trouble understanding the message (which is why I googled it). I wasn't aware that pyenv-virtualenv sets PS1 since I'm setting PS1 myself in my ~/.bashrc, and therefore export PYENV_VIRTUALENV_DISABLE_PROMPT=1 did nothing.
It's probably a good idea to either include information in the README on how users can set up their prompt themselves, or link to a guide somewhere else. In my setup, I'm using the $VIRTUAL_ENV variable, which I expect still will be available:
functionupdatePrompt {
# Styles
GREEN='\[\e[0;32m\]'
BLUE='\[\e[0;34m\]'
RESET='\[\e[0m\]'# Base prompt: \W = working dir
PROMPT="\W"# Current Git repoiftype"__git_ps1"> /dev/null 2>&1;then
PROMPT="$PROMPT$(__git_ps1 "${GREEN}(%s)${RESET}")"fi# Current virtualenvif [[ $VIRTUAL_ENV!="" ]];then# Strip out the path and just leave the env name
PROMPT="$PROMPT${BLUE}{${VIRTUAL_ENV##*/}}${RESET}"fi
PS1="$PROMPT\$"
}
export -f updatePrompt
# Bash shell executes this function just before displaying the PS1 variableexport PROMPT_COMMAND='updatePrompt'
Reacted by Jason Meridth, Joseph Bane, Fengyuan Chen, Zoom.Quiet, Dmitry Khodakov, Brent Payne, Mark Ibrahim, cid0rz, Falcon Dai, jaymz campbell and 41 more
@danmichaelo I agree (a link to) instructions should be included as it cannot be assumed that everyone who'd like to use pyenv-virtualenv knows how to write shell functions.
As said before, for beginners it's tricky enough to work out how to get tools like pyenv(-virtualenv) running in the first place; if we want more folks to use cool tools (which I hope we all do!) we need to make sure they are accessible.
I'll see if I can find time to try out your function, thanks for posting the code!
Reacted by Rithvik Vibhu, Steve Wang, Daniel Cosser, David Alberto Mena, Kim David Liedtke, Daniel Penalva and Alex M
@GandaG Copy and paste the code into a file named .bashrc (or .bash_profile) in your home folder should work. If you're not accustomed to these files, just google them.
@GandaG, you won't need that piece of code just yet, only once the prompt message is removed (in future versions). Though it might not actually be applicable anymore then. (; We'll see.
(I'll definitely want to keep the prompt change, so we might have to create our own workarounds in the future.)
@yyuu@kerstin@danmichaelo I'm sorry I came to this thread really late but, do you guys mean that pyenv activate/deactivate is no longer recommended and users should create .python-version and let pyenv handle virtualenv auto switching instead?
Reacted by Minh Lu, Aldy, Accidental Guru, John W. Miller, Matthew D. Scholefield, Tim Schwenke, Jonas Sander, Peter Hillerström, Xvezda, Ilia Postolaki and 6 more
Reacted by Accidental Guru, Ilia Postolaki, Michael Shepanski, phyng and Albert Mikaelyan
idk. if this is handy, but none of the other bash solutions quite replicate the default pyenv prompt behaviour in some way or another. I have put them together to do this which seems to work well. it hides the prompt if not in a virtualenv and revaluates with each new prompt - so it will change to be correct as you cd in and out of different envs and the system
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
if [[ "$(pyenv version-name)" != "system" ]]; then
export PS1='($(pyenv version-name)) '$BASE_PROMPT
else
export PS1=$BASE_PROMPT
fi
}
export PROMPT_COMMAND='updatePrompt'
adding this or similar to the README could be a reasonable substitute for removing/disabling the behaviour. although I'm not sure if this would work in shells other than bash?
Reacted by Asmus, NAKATA Keisuke and Egor Ryabkov
Reacted by Asmus, NAKATA Keisuke, Luke Tainton and Melissa Lewis
@LukeAI Thank you for providing the solution!
I had to make a few changes to make it work (I am using zsh).
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
if [[ "$(pyenv version-name)" != "system" ]]; then
# the next line should be double quote; single quote would not work for me
export PS1="($(pyenv version-name)) "$BASE_PROMPT
else
export PS1=$BASE_PROMPT
fi
}
export PROMPT_COMMAND='updatePrompt'
precmd() { eval '$PROMPT_COMMAND' } # this line is necessary for zsh
Reacted by rtur, kbehlers, Bo Johnson, NUMAGA, Noah Santacruz, Sam Lim, jayzane, ScrambledRK and yakzan
Reacted by Hotea and yakzan
Reacted by Hotea, Tom Clark, Sarosh Ahmad, Melissa Lewis, Vitalie Spinu and yakzan
In cases where you have multiple version specified in .python-version the prompt gets really long. Amending the commented lines below allowed me to just show the first version listed in the file:
eval"$(pyenv init -)"eval"$(pyenv virtualenv-init -)"# turn off deprecated pyenv promptexport PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1functionupdatePrompt {
if [[ "$(pyenv version-name)"!="system" ]];then
PYENV_VER=$(pyenv version-name)# capture version name in variableexport PS1="(${PYENV_VER%%:*}) "$BASE_PROMPT# grab text prior to first ':' characterelseexport PS1=$BASE_PROMPTfi
}
export PROMPT_COMMAND='updatePrompt'
I've done this one based on @LukeAI's answer, where it will only print the active env name by finding it in the list that pyenv virtualenvs returns. Therefore, system won't be printed, and neither will the pyenv project version.
Would it be acceptable to keep the current behaviour but disable the warning, at least until the release happens, by setting export PYENV_VIRTUALENV_DISABLE_PROMPT=0? It could raise an error after the release is done if this behaviour is no longer supported.
Reacted by Luis, Xinyang Zhu, Artur Martins, Patrick Wright and Daniel Wolf
These solutions kinda slowed down my shell on every command press so I had to revert. When I realized this originated in 2015 I was delighted in a way b/c it doesn't look like this default functionality will be removed since it hasn't been changed thus far.
Activity
yyuu commentedon Dec 28, 2015
In pyenv-virtualenv prior to v20151222, there were some known issues related to management of
$PATHand shell's prompt (#51, #69, #80).To solve all those issues intrinsically, pyenv-virtualenv stopped using
activatescript generated by virtualenv, venv and conda env (#104). The virtual environments will be pick up via shims just like other ordinary versions in pyenv (e.g.2.7.11,3.5.1, etc.). Because these virtual environments are just a pyenv version now, I don't like to do something special for them as much as possible. I added that deprecation warning and I will remove the prompt changing feature in future releases (actually, the feature has already been removed forfishshell since it had known problem).https://github.com/yyuu/pyenv-virtualenv/blob/v20151222/bin/pyenv-sh-activate#L221
Now you can see what virtual environment (or a version) is activated from the output of
pyenv versions, like other non-virtual versions in pyenv. Any users can configure their shell to show the name of activated virtualenv in their prompt like before, but pyenv-virtualenv will stop doing it by default in future release.Any contributions are always welcomed. We need more hands and eyes to improve things, especially for documentation since I am pretty bad at documentation 😛
keikoro commentedon Dec 28, 2015
I'm still not sure if I understand fully. (;
So, you won't remove the code for changing the prompt entirely (that's how the message read to me!), but the prompt change won't be the default anymore and users will have to (re)enable it via their shell (with the
PYENV_VIRTUALENV_DISABLE_PROMPTvariable)?Is that it? And will that affect both the 'activate/deactivate' messages and the display of the virtualenv's name? (Meaning: does the variable cover both, or is it possible to only get the name displayed and not the activate/deactivate messages?)
Regarding the documentation: yeah, I'd especially like for it (any documentation, really!) to be as beginner-friendly as possible. (: So, not leaving out any info that might be helpful for people not (so) familiar with certain tools, or the lingo that comes with them.
I'd really love to see more programming beginners use Homebrew & pyenv (or chruby etc.) from the beginning as I believe it's generally a good idea not to mess with one's Mac system too much. But, for beginners, info on additional tools and how to use them can be quite overwhelming (and missing 'helper' messages can make navigation/usage of tools more difficult). So if I'm struggling with any of this, it must be n times harder for total beginners! And I'm afraid they're then more likely to just not go through all the trouble of trying to figure out how to do things (better).
Anyway, cool, I'll change that one bit I was looking to change soon, and submit a PR!
yyuu commentedon Dec 29, 2015
I didn't say I won't remove it. It's just keep for now for compatibility between previous release.
keikoro commentedon Dec 31, 2015
Oh, so are you planning to remove it altogether? That would be a pity. ): It's a really, really useful feature to have.
Btw. I thought about the issue some more, trying to figure out why I found the current instructions so confusing. I think it's because the variable says 'disable' for a function which will be disabled by default anyway!
People will have to 'disable' something that's already disabled, when really, they want to turn on something that's turned off by default. I.e. wouldn't it make more sense to name it
PYENV_VIRTUALENV_ENABLE_PROMPTand have people set it to 0 in their shell config if they want to (re)enable the prompt?danmichaelo commentedon Jan 2, 2016
I guess the
PYENV_VIRTUALENV_DISABLE_PROMPTvariable is just a temporary solution to let you test how it will be once the feature is removed. It will probably go away together with the feature.Anyways, I also had a little trouble understanding the message (which is why I googled it). I wasn't aware that pyenv-virtualenv sets PS1 since I'm setting PS1 myself in my
~/.bashrc, and thereforeexport PYENV_VIRTUALENV_DISABLE_PROMPT=1did nothing.It's probably a good idea to either include information in the README on how users can set up their prompt themselves, or link to a guide somewhere else. In my setup, I'm using the
$VIRTUAL_ENVvariable, which I expect still will be available:keikoro commentedon Jan 2, 2016
@danmichaelo I agree (a link to) instructions should be included as it cannot be assumed that everyone who'd like to use pyenv-virtualenv knows how to write shell functions.
As said before, for beginners it's tricky enough to work out how to get tools like pyenv(-virtualenv) running in the first place; if we want more folks to use cool tools (which I hope we all do!) we need to make sure they are accessible.
I'll see if I can find time to try out your function, thanks for posting the code!
dh-nunes commentedon Feb 19, 2016
@danmichaelo @kerstin newbie here, how can I use that shell function to have the prompt like virtualenv's? Thanks :D
danmichaelo commentedon Feb 20, 2016
@GandaG Copy and paste the code into a file named
.bashrc(or.bash_profile) in your home folder should work. If you're not accustomed to these files, just google them.dh-nunes commentedon Feb 20, 2016
@danmichaelo thanks! The prompt appeared after restarting so I guess I better not change anything (I have this bookmarked though)
keikoro commentedon Feb 21, 2016
@GandaG, you won't need that piece of code just yet, only once the prompt message is removed (in future versions). Though it might not actually be applicable anymore then. (; We'll see.
(I'll definitely want to keep the prompt change, so we might have to create our own workarounds in the future.)
Fix prompt change for pyenv-virtualenv
athrunsun commentedon Dec 26, 2016
@yyuu @kerstin @danmichaelo I'm sorry I came to this thread really late but, do you guys mean that
pyenv activate/deactivateis no longer recommended and users should create.python-versionand let pyenv handle virtualenv auto switching instead?yyuu commentedon Dec 26, 2016
@athrunsun only virtualenv like prompt changing feature has been deprecated.
I don't have any plan to deprecate
pyenv activateandpyenv deactivate. They should work as long as pyenv'sPYENV_VERSIONenvironment variable works.athrunsun commentedon Dec 26, 2016
@yyuu Thanks. It looks I can change to a specific virtualenv by
pyenv shellas well, which is more convenient.11 remaining items
millerdev commentedon Jun 11, 2020
In the mean time I added a simple function to .bashrc
Usage:
workon VENV_NAMEShout-out to virtualenvwrapper!
LukeAI commentedon Sep 29, 2020
idk. if this is handy, but none of the other bash solutions quite replicate the default pyenv prompt behaviour in some way or another. I have put them together to do this which seems to work well. it hides the prompt if not in a virtualenv and revaluates with each new prompt - so it will change to be correct as you
cdin and out of different envs and the systemadding this or similar to the README could be a reasonable substitute for removing/disabling the behaviour. although I'm not sure if this would work in shells other than bash?
chunyunma commentedon Oct 20, 2020
@LukeAI Thank you for providing the solution!
I had to make a few changes to make it work (I am using zsh).
rmorshea commentedon Oct 27, 2020
In cases where you have multiple version specified in
.python-versionthe prompt gets really long. Amending the commented lines below allowed me to just show the first version listed in the file:JinYeJin commentedon Dec 15, 2020
So after of all, I don't need to concern that warning, right?
keisuke-nakata commentedon Jan 5, 2021
I have slightly modified @rmorshea 's script, for people who change the global environment from
system:| paste -sd ':' -is needed becausepyenv globalprints line-break separated virtualenv names.ollie-bell commentedon May 9, 2021
Solution that leaves the pyenv-virtualenv behavior untouched, but just sends the warning message to
/dev/nullsed -i '/prompt changing will be removed from future release/s/1>&2/> \/dev\/null/' ~/.pyenv/plugins/pyenv-virtualenv/bin/pyenv-sh-activateroytseng-tw commentedon Jun 13, 2021
For those who use pyenv + poetry
saya-rbt commentedon Oct 25, 2021
I've done this one based on @LukeAI's answer, where it will only print the active env name by finding it in the list that
pyenv virtualenvsreturns. Therefore,systemwon't be printed, and neither will thepyenvproject version.I hope it helps!
current-liu commentedon Apr 8, 2022
The only thing need todo is to rm the warning msg.
nate-kean commentedon Jul 10, 2022
So... is this "future release" still coming, or has this message annoyed thousands of people over the course of seven years for no reason?
native-api commentedon Jul 10, 2022
@yyuu , I believe you're in the best position to answer this 🙂
m-legrand commentedon Aug 13, 2022
Would it be acceptable to keep the current behaviour but disable the warning, at least until the release happens, by setting
export PYENV_VIRTUALENV_DISABLE_PROMPT=0? It could raise an error after the release is done if this behaviour is no longer supported.jeff-zone commentedon Feb 9, 2023
These solutions kinda slowed down my shell on every command press so I had to revert. When I realized this originated in 2015 I was delighted in a way b/c it doesn't look like this default functionality will be removed since it hasn't been changed thus far.
sun-mir commentedon Apr 5, 2024
Kudos to @native-api
🥹
#447
Hoping it will make it to homebrew as well 🤞
Homebrew/homebrew-core#165989