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

Python: cannot deactivate environments in Terminal #3043

Open
isabelizimm opened this issue May 7, 2024 · 3 comments
Open

Python: cannot deactivate environments in Terminal #3043

isabelizimm opened this issue May 7, 2024 · 3 comments
Labels
bug Something isn't working lang: python

Comments

@isabelizimm
Copy link
Contributor

Positron Version:

Positron dev

Steps to reproduce the issue:

  1. Start up Terminal
  2. Try to deactivate current environment/activate a new one
  3. See output
Screenshot 2024-05-07 at 10 33 16 AM

I believe this is a side effect of python.terminal.activateEnvironment setting. By the time I have tried to activate one environment, I have 3 environments displayed, and the one I have activated is not actually the one in use.

What did you expect to happen?

Python environments to deactivate properly.

Were there any error messages in the output or Developer Tools console?

None

@isabelizimm isabelizimm added bug Something isn't working lang: python labels May 7, 2024
@seeM
Copy link
Contributor

seeM commented May 8, 2024

Could you please share more about your environment management setup? Specifically, what's executed in your bashrc/zshrc and corresponding _profile files?

What happens if you repeat this in VSCode (ensuring the same python.terminal.activateEnvironment setting and that you opt into the same experiment we do)? I recall seeing issues about deactivation in the upstream repo so may also be worth exploring those.

@isabelizimm
Copy link
Contributor Author

In VSCode, with python.terminal.activateEnvironment, conda (base) is activated automatically every new terminal I open. This occurs in Positron as well, since it is being activated in my .zshrc/.bash_profile. The difference is, in Positron, the pyenv interpreter is also activated + nested automatically.

In VSCode:

### START OF TERMINAL:
(base) ➜   pyenv activate positron
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(positron) (base) ➜   pyenv activate pydemo  
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(pydemo) (base) ➜   which python
/Users/isabelzimmerman/.pyenv/versions/3.11.4/bin/python
(pydemo) (base) ➜   

In Positron:

### START OF TERMINAL:
((positron) ) (base) ➜  pyenv activate pydemo
pyenv-virtualenv: virtualenv `/Users/isabelzimmerman/.pyenv/versions/3.10.7/envs/positron' is already activated
((positron) ) (base) ➜  pyenv deactivate     
((positron) ) (base) ➜  pyenv activate pydemo
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(pydemo) ((positron) ) (base) ➜  which python
/Users/isabelzimmerman/.pyenv/versions/3.10.7/envs/positron/bin/python
(pydemo) ((positron) ) (base) ➜   

Do note that neither of these are really doing what I want them to; pydemo is Python 3.9.12, positron is Python 3.10.7, and my global pyenv is Python 3.11.4. My startup interpreter is positron. In that sense, Positron is actually closer to choosing the right Python than VSCode 😅

I suppose my largest issues here are

  1. conda is activated, even when it is not my selected interpreter (maybe that is not something Positron can/should do, if it includes overwriting zshrc/bashrc settings)
  2. multiple interpreters showing when i try to activate/deactivate
  3. nested interpreters (potentially fixed upstream, see related issues)

Related upstream discussions:


With pyenv AND conda installed, I do have a bit of a mess in these files.

I've pulled out the pyenv + conda pieces for the following files:

~/.zshrc

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/isabelzimmerman/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/isabelzimmerman/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/isabelzimmerman/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/isabelzimmerman/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

~/.bashrc

nothing pyenv or conda related

~/.zprofile

nothing pyenv or conda related

~/.bash_profile

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/opt/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/opt/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

@petetronic petetronic added this to the Release Candidate milestone May 13, 2024
@jthomasmock
Copy link
Contributor

Also ran into this:

Not sure if this is same, but I have observed this behavior, where it looks like you are in a venv, but unable to deactivate.

# initial load of a new zsh shell
# ------

(.venv) 

~/demo-video [🐍pyenv 3.12.0 (.venv)][2024-18-06  8:56AM]
❯ which python
/Users/thomasmock/demo-video/.venv/bin/python
(.venv) 

~/demo-video [🐍pyenv 3.12.0 (.venv)][2024-18-06  8:56AM]
❯ deactivate
zsh: permission denied: deactivate
(.venv) 

~/demo-video [🐍pyenv 3.12.0 (.venv)][2024-18-06  8:56AM]
❯ source .venv/bin/activate
(.venv) 

~/demo-video [🐍pyenv 3.12.0 (.venv)][2024-18-06  8:56AM]
❯ which python             
/Users/thomasmock/demo-video/.venv/bin/python
(.venv) 

~/demo-video [🐍pyenv 3.12.0 (.venv)][2024-18-06  8:56AM]
❯ deactivate               
(.venv) 

~/demo-video [2024-18-06  8:56AM]
❯ which python
/Users/thomasmock/demo-video/.venv/bin/python
(.venv) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang: python
Projects
None yet
Development

No branches or pull requests

4 participants