1

My shell prompt is read-only, so when trying to activate a venv, I get

source myenv/bin/activate
-bash: PS1: readonly variable

Looking at the docs here

https://virtualenv.pypa.io/en/stable/reference/#envvar-VIRTUAL_ENV_DISABLE_PROMPT

Any virtualenv created when this is set to a non-empty value will not have it’s activate script modify the shell promp

So, I deleted the venv, ran

export VIRTUAL_ENV_DISABLE_PROMPT=1

and recreated the virtual environment,

virtualenv myenv

but it still shows

-bash: PS1: readonly variable

When I try to source it.

The variable seems to be set correctly

env | grep VIRTUAL_ENV_DISABLE
VIRTUAL_ENV_DISABLE_PROMPT=1

What am I doing wrong here?

chrise
  • 4,039
  • 3
  • 39
  • 74
  • What command did you use to create env? – funnydman Jan 09 '19 at 06:48
  • Possible duplicate of [Unset readonly variable in bash](https://stackoverflow.com/questions/17397069/unset-readonly-variable-in-bash) – heemayl Jan 09 '19 at 06:51
  • @FUNNYDMAN virtualenv spxenv – chrise Jan 09 '19 at 06:59
  • @heemayl I am on a shared user account, so I cant use any hacky ways to change the status of the prompt. This is why I am trying make the venv not modify the prompy – chrise Jan 09 '19 at 07:00
  • Can you run `set -x` and then the `activate` command, and see where exactly it tries to modify your PS1 still? (`set +x` to return to normal.) – tripleee Jan 09 '19 at 07:14
  • 1
    It appears the export PS1 in the deactivate() function gave the trouble. Although I dont see why this would be called – chrise Jan 09 '19 at 07:29
  • In my copy it calls `deactivate nondestructive` as part of the main flow when you `activate`, probably to undo any previously active virtualenv before switching to the one you want. It goes with a comment with a hilarious misspelling of "irrelevant" (line 37 in my copy). – tripleee Jan 09 '19 at 07:32

1 Answers1

0

Update ./bin/activate script to skip updating PS1 variable:

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
    _OLD_VIRTUAL_PS1="$PS1"
    if [ "x" != x ] ; then
        #PS1="$PS1"
    else
        #PS1="(`basename \"$VIRTUAL_ENV\"`) $PS1"
    fi
    #export PS1
fi
napuzba
  • 6,033
  • 3
  • 21
  • 32