posit-dev / positron

Positron, a next-generation data science IDE
Other
2.4k stars 70 forks source link

Python: Changing Positron's interpreter does not affect new terminal's `PATH` #1491

Closed seeM closed 8 months ago

seeM commented 11 months ago

Positron Version:

Positron Version: 2023.09.0 (Universal) build 3831

Steps to reproduce the issue:

  1. Run "Python: Select Interpreter" and note the currently highlighted interpreter.
  2. If you now open a new terminal and enter which python it should also point to the above interpreter's path, since PATH should contain that interpreter's /bin folder (e.g. /Users/seem/.pyenv/versions/3.7.16/bin) early in the path list.
  3. Use Positron's interpreter picker to select a different interpreter.
  4. Open a new terminal and run which python, it should be unchanged from step 2.

What did you expect to happen?

The active interpreter in a new terminal should match Positron's interpreter.

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

No

isabelizimm commented 9 months ago

Would it make sense to open a new terminal, rather than swapping an existing terminal's path? You can add custom names to terminals, so something like this?

Screenshot 2023-12-18 at 1 55 27 PM

It might get a little noisy, but it would be safer than overwriting existing paths if users are actively working in a terminal. And, you would only ever need 1 terminal per interpreter?

jgutman commented 9 months ago

I'd also like to note that for me, they don't match on Positron startup, even if I haven't changed my interpreter. For example, if I open a new Positron (without any Python files/workspaces open that I've previously changed the interpreter on), it chooses Python 3.11.5 (Global) in /usr/local/bin/python as my default interpreter. But in my terminal (zsh), which python is set to ~/.pyenv/shims/python version 3.10.11, which is listed in the interpreter list as 3.10.11 (Pyenv) ~/.pyenv/versions/3.10.11/bin/python. So not only that changing the interpreter doesn't affect the terminal's path, but also, I get a mismatch between terminal path and interpreter python path immediately on startup, and I actually have to change my interpreter every time to get it to match my terminal.

I suspect this is specific to pyenv and having this in my zshrc

# Default python
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

but I don't think that's an uncommon user scenario

seeM commented 9 months ago

@isabelizimm I agree we shouldn't fiddle with the user's PATH. My intention for this issue was to align Positron's idea of the active Python interpreter with vscode-python's.

I really like the idea of opening a new terminal with a custom name! It might also need something like https://github.com/posit-dev/positron/issues/1492 to let the user know that the current one is "stale". It might be worth opening a separate issue for this. Do you know if this would be useful in R too? If so, would be good to get a broader discussion going.

@jgutman great catch, ty! I'll look into the startup behaviour at the same time.

jgutman commented 9 months ago

My thought on whether it would be useful in R: its much less common for a user to use R from the command line. It's certainly possible, but not as common as a python user wanting to run a pip or python command that will match the active interpreter. So I don't imagine it being nearly as valuable there

jennybc commented 9 months ago

I think this would probably have more downside than upside for R, FWIW. As @jgutman says, I think the prototypical R user is often running it via RStudio or Positron or Emacs or what have you, not with a bare R in the terminal.

I've recently gotten very in touch with how the "current" version of R is rigged on various operating systems and, on Windows for example, that is not usually even done via the PATH, but instead using the registry.

isabelizimm commented 8 months ago

confirmed that switching Positron interpreter activates the environment in the terminal tab! If I have multiple terminals open, it will switch to the new interpreter in all of them