简体   繁体   English

在终端启用 pyenv-virtualenv 提示符

[英]Enable pyenv-virtualenv prompt at terminal

I just installed pyenv and virtualenv following: https://realpython.com/intro-to-pyenv/我刚刚安装了 pyenv 和 virtualenv 如下: https://realpython.com/intro-to-pyenv/

After completing installation I was prompted with:完成安装后,系统提示我:

pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior

I added export PYENV_VIRTUALENV_DISABLE_PROMPT=1 to my .bash_aliases just to see what the behavior would be, and sure enough it removed the prompt that used to exist at the beginning of the command prompt indicating the pyenv-virtualenv version.我将export PYENV_VIRTUALENV_DISABLE_PROMPT=1添加到我的.bash_aliases只是为了查看行为是什么,并且确实删除了曾经存在于命令提示符开头的指示 pyenv-virtualenv 版本的提示符。 Used to be like:曾经是这样的:

(myenv) user@foo:~/my_project [main] $

where (myenv) is the active environment, and [main] is the git branch.其中(myenv)是活动环境, [main]是 git 分支。

I would love to have the environment indicator back.我很想恢复环境指标。 It is very useful: I guess at some possibilities such as:这非常有用:我猜想有一些可能性,例如:

export PYENV_VIRTUALENV_DISABLE_PROMPT=0

export PYENV_VIRTUALENV_ENABLE_PROMPT=1

But these do not return the previous behavior.但是这些不会返回以前的行为。 I have googled all over and can't figure out how to get this back.我到处搜索,无法弄清楚如何取回它。

This answer is not useful, as it seems like a hack around the original functionality, and displays the environment always, not just when I enter (or manually activate) an environment. 这个答案没有用,因为它似乎是对原始功能的破解,并且始终显示环境,而不仅仅是在我进入(或手动激活)环境时。

Borrowing a solution from here , the following works (added to .bashrc or .bash_aliases ):这里借用一个解决方案,以下工作(添加到.bashrc.bash_aliases ):

export PYENV_VIRTUALENV_DISABLE_PROMPT=1
export BASE_PROMPT=$PS1
function updatePrompt {
    if [[ "$(pyenv virtualenvs)" == *"* $(pyenv version-name) "* ]]; then
        export PS1='($(pyenv version-name)) '$BASE_PROMPT
    else
        export PS1=$BASE_PROMPT
    fi
}
export PROMPT_COMMAND='updatePrompt'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pyenv-virtualenv 中的环境变量 - Enviroment variables in pyenv-virtualenv pyenv-virtualenv:pyenv中未安装“ 3.6.4” - pyenv-virtualenv: `3.6.4' is not installed in pyenv 使用pyenv-virtualenv触发不同的应用环境 - triggering different app environments with pyenv-virtualenv 带有pyenv-virtualenv的VSCode,自动触发? - VSCode with pyenv-virtualenv, trigger automatically? 使用 pyenv-virtualenv 设置 virtualenv 时出现 ASCII 编解码器错误 - ASCII codec error when setting up an virtualenv with pyenv-virtualenv 在`pyenv/pyenv-virtualenv`中,我可以创建一个引用`system`的virtualenv,即之前没有`pyenv install`吗? - in `pyenv/pyenv-virtualenv` can I create a virtualenv which refers to `system`, i.e. without a `pyenv install` before? 从 pyenv-virtualenv 切换到 pipeenv 时保持相同的共享虚拟环境 - Keeping the same, shared virtualenvs when switching from pyenv-virtualenv to pipenv 在pyenv-virtualenv上激活虚拟环境时,如何导出PYTHONPATH? - How to export PYTHONPATH when I activate a virtual environment on pyenv-virtualenv? pyenv-virtualenv 的问题:激活/停用虚拟环境时 Python 和 PIP 未更改 - Issues with pyenv-virtualenv: Python and PIP not changed when activating / deactivating virtual environment pyenv或virtualenv对Django是必不可少的吗? - Is pyenv or virtualenv essential for Django?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM