Repository navigation
Description
On a fresh installation of the IDE and reticulate on macOS, reticulate will default to discovering the system python /usr/bin/python3 in the IDE. This is not consistent with the guidance we provide elsewhere for users to prefer working in virtual environments.
This happens because the option "Python > Automatically activate project-local Python environments" is checked by default. When this option is checked, even in projects where there is no project-local configured python, the IDE will set env var RETICULATE_PYTHON_FALLBACK, to what it finds: /usr/bin/python3.
When the system python is selected by the IDE like this, it also adjusts PATH by prepending /usr/bin, masking manually installed and preferred executables under /usr/local/bin.
(e.g., https://positpbc.slack.com/archives/CTACV7WC9/p1688650055493939?thread_ts=1688588487.673509&cid=CTACV7WC9, #12787)
If the IDE did not set this env var in this situation, then reticulate would continue along the documented "Order of Discovery", prompt the the user to create a "r-reticulate" venv, and default to using that.
It's not clear to me what is best to do here. Some loose thoughts about potential changes:
- Maybe this checkbox should be unchecked by default? With the latest release, reticulate will now automatically discover a project local venv, perhaps the IDE doesn't need to do this by default anymore?
- If we leave it checked by default, maybe the checkbox should only automatically discover interpreters in the project directory, and not venture out of the project directory to find the system python, unless explicitly asked to do so by the user? If checked, and not pointed at a specific python by the user, and if the IDE doesn't find a python in the project directory, then perhaps the IDE should leave the env var
RETICULATE_PYTHON_FALLBACK(and other env vars likeVIRTUAL_ENV) unset. - If the checkbox is checked, the "Python Interpreter" box in the GUI preference pane should indicate which interpreter is being set by the IDE, instead of "(No interpreter selected)".
- Maybe, if we default it to off, the IDE option should switch to setting
RETICULATE_PYTHONinstead ofRETICULATE_PYTHON_FALLBACKfor the user? Note thatVIRTUAL_ENV, also set by the IDE when the checkbox is checked, is earlier in reticulates order of discovery thanRETICULATE_PYTHON_FALLBACK.
Activity
kevinushey commentedon Sep 5, 2023
For reference:
rstudio/src/cpp/session/modules/SessionPythonEnvironments.R
Lines 119 to 212 in b91450d
Maybe we should remove the code here?
rstudio/src/cpp/session/modules/SessionPythonEnvironments.R
Lines 192 to 207 in b91450d
jonvanausdeln commentedon Sep 12, 2023
Since we are so close to Desert Sunflower release, moving to Ocean Storm
jonvanausdeln commentedon Nov 7, 2023
Verified with 2023.12.0-daily+266
MacOS 13, Ubuntu22
The correct Python interpreter appears to be activated