-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use the previously specified interpreter for a project regardless of environment #20644
Comments
Can you please attach the output from the Python channel in the Output panel (or get all the details that the |
I think I'm having a related issue. Since this last update, all of my projects open with the default interpreter. I can select the right interpreter, and that works for the session. But when VS code is restarted, it doesn't remember the correct interpreter and opens the project with the default. All of the interpreters (including the one that gets defaulted to) are conda environments. I'm using MacOS: 12.6.3
Output of python extension when I open a project and set the interpreter to
Output when I reopen the project and it defaults to the
Output of the Jupyter extension when VS code starts and defaults to
|
Output panel logs would still be appreciated. |
@brettcannon sorry, updated. the line |
Dealing with the same exact issue right now, switching to the pre-release version of the extension seems to have fixed the issue. |
@brettcannon |
fyi it doesn't look like the output from the python extension was automatically included |
Prerelease v2023.3.10341119 doesn't change the behavior for me |
Update If I open Visual Studio Code by simply clicking on the icon instead from terminal it will load everything correctly (but only after I manually select recommended interpreter manually), built in terminal will also have activated virtual environment, here is the output:
To be clear what's going on:
I select manually recommended interpreter that fixes the issue
and now what's interesting, sometimes it will open without the issue, sometimes there will be a problem: Also I noticed that when I select correct interpreter after opening via terminal that fixes the import problem, built in terminal won't have activated virtual environment (If I create a new terminal after selecting correct interpreter with the @maurczz can you test it? |
@zebra-f Sorry I don't quite understand the issue with your original bug report #20644 (comment). The Interpreter you intend to select |
@daeh Actually yes, although we only intend to do it when You temporarily fix the issue by reverting to previous version of the extension. Follow the prompts from "Extensions: Install Specific Version of Extension..." in the command palette: |
@karrtikr me neither, but as I have said, there is a problem- Here is the output when I get lucky reopening with
well only |
https://streamable.com/bp75s5 sorry for the quality, but important parts should be visible. |
Thanks, I understand the problem. Pylance and isort are using the wrong path to executable, I'll open the respective issues on their end. |
Can you provide the isort logs from the output panel? Alternatively, you can open an issue here https://github.com/microsoft/vscode-isort. |
Opening with problems:
Opening without problems:
|
There isn't just one environment I intend to use as the interpreter. I have about a dozen active projects and they each use a dedicated conda interpreter. Previously, when I opened a project it used the correct interpreter, but now they all default to the |
@daeh Gotcha. Instead of |
thanks @karrtikr . The Before this extension issue started, the User Maybe also worth being explicit: I'm opening VS Code by clicking the icon in the MacOS doc. I'm not launching vscode from a system terminal window. |
@daeh Thanks, turning this into a feature request to provide a way to override the automatic selection of activated environment at startup. We are going to give the community 60 days from when this issue was created to provide 7 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@karrtikr a bunch of my lab mates use a similar shell env, so I let people know that this issue was under consideration on our slack channel. Those are the upvotes, (the spam comment was obviously unrelated). |
Thanks for clarifying, we'll consider this. |
thanks @karrtikr, would be helpful for lots of us. |
thanks, fwiw, I might rephrase the feature request title. For me, it's about having a way to specify the interpreter for a project that overrides the defaults (e.g. the conda env activated in I think it's fine to select the activated environment as the interpreter by default when no interpreter is specified by a user. So I might rename the FR "Remember user specification of interpreter for a project". Appreciate the help, @karrtikr |
Please feel free to! This is still your feature request, so please change the title and opening comment to better reflect what you're asking.
I would append "regardless of environment" since we have, up to this point, always done that. The tricky bit for us is gleaming intent. If you launched VS Code from a terminal with an activated environment, were you showing intent that you wanted VS Code to use that environment (since you put in the effort to activate it), or did you have an "accidental" activation and that wasn't really meant for VS Code to care about when a previous action within VS Code showed your intent of preferred environment? We obviously went with the former at launch, but I'm interpreting your feature request as wanting the latter. |
(I'm actually not the OP, that's @zebra-f . @karrtikr changed the title to what it is currently. But @zebra-f , if you're up for it, maybe you can change the title to "Remember user specification of interpreter for a project regardless of environment"?)
Yeah, I 100% got that. (Again, FWIW in my case I'm just clicking on the VS code Icon in the dock, or opening a workspace from the File menu, not launching vscode from a system terminal window.) |
Sorry about that! I have gone ahead and changed the title.
Is this specifically upfront, or are you okay if we pick up your conda environment the first time from your environment, time you change it to something else, and we remember what you selected going forward and let that override what the environment is set to? Because if you're trying to pull in |
the easy thing. I just want it remembered going forward when I change it. |
We have a PR by @karrtikr linked to this issue where we don't do the environment detection when you don't launch from a terminal (i.e. a double-click of an icon, launching from the Dock in macOS, etc.). Would that fix your issue? |
yep! |
prerelease works great for me. Thank you @karrtikr ! |
So I have a question. If I want a project to use a specified python interpreter, how do I set up or start the project? I don't seem to find a solution in this article. |
@ydmykr you can use |
@brettcannon However, according to the document about vscode-python, I want to be able to set the specified workspace instead of global. I can open a new issue if necessary, thanks alot. |
-------------------- Commit message for microsoft/vscode-python@fc72be9: Show `Python: Report issue` command in palette regardless of whether a Python file is opened (microsoft/vscode-python#20726) Closes microsoft/vscode-python#20723 -------------------- Commit message for microsoft/vscode-python@c18e8c9: Detect ActiveState Python runtimes (microsoft/vscode-python#20534) Closes microsoft/vscode-python#20532 -------------------- Commit message for microsoft/vscode-python@2152cd9: Don't set `formatOnType` for auto-indent experiment if it's already set (microsoft/vscode-python#20710) -------------------- Commit message for microsoft/vscode-python@995b0bc: Add support for 'back' to all create env UI. (microsoft/vscode-python#20693) Closes microsoft/vscode-python#20274 ### Usage This change allows callers of the Create Environment command to handle `Back` and `Cancel`: ``` typescript let result: CreateEnvironmentResult | undefined; try { const result = await commands.executeCommand("python.createEnvironment", {showBackButton: true}); } catch(e) { // error while creating environment } if (result?.action === 'Back') { // user clicked Back } if (result?.action === 'Cancel') { // user pressed escape or Cancel } ``` I decided to go with `result?.action` because we don't have a npm package for python extension API so catching particular exception might be error prone with `ex instanceof <error>`. We will provide a proper interface via `api.environments` for create environment, and contribution to create environment. Until that point this command will provide the stop gap. ### Notes 1. I did not use the multi-step input that is used in the rest of the extension because, the existing implementation does not have context. Consider the following scenario: venv -> workspace select -> python select -> packages. Assume that there is only one workspace, and we don't show the workspace selection UI, that decision is done inside the workspace step. So, if there is only 1 workspace it is a short circuit to next step. User is on python selection and clicks `back`, workspace selection short circuits to next step which is python selection. So, from user perspective, back does not work. This can be fixed by sending context that the reason control moved to previous step was because user clicked on back. 2. This makes a change to old multi step API to rethrow the exception, if user hits `back` and the current step has no steps to go back to. -------------------- Commit message for microsoft/vscode-python@f3ecbf5: Fix-conda-version-parsing (microsoft/vscode-python#20674) -------------------- Commit message for microsoft/vscode-python@a6a6f50: Inactive pytest run command (microsoft/vscode-python#20653) Here the new flow is created but kept inactive for the pytest execution -------------------- Commit message for microsoft/vscode-python@2202fbe: Call the correct API to determine if a user is in treatment or control group (microsoft/vscode-python#20690) Closes microsoft/vscode-python#20183 -------------------- Commit message for microsoft/vscode-python@b0ab10d: Only use activated environment from terminal if VSCode was launched via CLI (microsoft/vscode-python#20667) Closes microsoft/vscode-python#20644 -------------------- Commit message for microsoft/vscode-python@02a92fc: Ensure interpreter path isn't truncated for workspace-relative paths when storing value (microsoft/vscode-python#20661) For microsoft/vscode-python#20660 I'm not quite sure why this was done. It doesn't make sense to do this only for display. -------------------- Commit message for microsoft/vscode-python@377067f: Use correct API to get interpreter path for language servers (microsoft/vscode-python#20656) For microsoft/vscode-python#20644 closes microsoft/vscode-python#20657 -------------------- Commit message for microsoft/vscode-python@cd6ca9d: Remove `isort` extension dependency (microsoft/vscode-python#20577) Closes microsoft/vscode-python#20586 Lead-authored-by: Kartik Raj <karraj@microsoft.com> Co-authored-by: Erik De Bonte <erikd@microsoft.com> Co-authored-by: Karthik Nadig <kanadig@microsoft.com> Co-authored-by: mitchell <mitchellb@activestate.com> Co-authored-by: Pete Farland <pete.farland@posit.co> Co-authored-by: Eleanor Boyd <eleanorboyd@microsoft.com>
-------------------- Commit message for microsoft/vscode-python@fc72be9: Show `Python: Report issue` command in palette regardless of whether a Python file is opened (microsoft/vscode-python#20726) Closes microsoft/vscode-python#20723 -------------------- Commit message for microsoft/vscode-python@c18e8c9: Detect ActiveState Python runtimes (microsoft/vscode-python#20534) Closes microsoft/vscode-python#20532 -------------------- Commit message for microsoft/vscode-python@2152cd9: Don't set `formatOnType` for auto-indent experiment if it's already set (microsoft/vscode-python#20710) -------------------- Commit message for microsoft/vscode-python@995b0bc: Add support for 'back' to all create env UI. (microsoft/vscode-python#20693) Closes microsoft/vscode-python#20274 ### Usage This change allows callers of the Create Environment command to handle `Back` and `Cancel`: ``` typescript let result: CreateEnvironmentResult | undefined; try { const result = await commands.executeCommand("python.createEnvironment", {showBackButton: true}); } catch(e) { // error while creating environment } if (result?.action === 'Back') { // user clicked Back } if (result?.action === 'Cancel') { // user pressed escape or Cancel } ``` I decided to go with `result?.action` because we don't have a npm package for python extension API so catching particular exception might be error prone with `ex instanceof <error>`. We will provide a proper interface via `api.environments` for create environment, and contribution to create environment. Until that point this command will provide the stop gap. ### Notes 1. I did not use the multi-step input that is used in the rest of the extension because, the existing implementation does not have context. Consider the following scenario: venv -> workspace select -> python select -> packages. Assume that there is only one workspace, and we don't show the workspace selection UI, that decision is done inside the workspace step. So, if there is only 1 workspace it is a short circuit to next step. User is on python selection and clicks `back`, workspace selection short circuits to next step which is python selection. So, from user perspective, back does not work. This can be fixed by sending context that the reason control moved to previous step was because user clicked on back. 2. This makes a change to old multi step API to rethrow the exception, if user hits `back` and the current step has no steps to go back to. -------------------- Commit message for microsoft/vscode-python@f3ecbf5: Fix-conda-version-parsing (microsoft/vscode-python#20674) -------------------- Commit message for microsoft/vscode-python@a6a6f50: Inactive pytest run command (microsoft/vscode-python#20653) Here the new flow is created but kept inactive for the pytest execution -------------------- Commit message for microsoft/vscode-python@2202fbe: Call the correct API to determine if a user is in treatment or control group (microsoft/vscode-python#20690) Closes microsoft/vscode-python#20183 -------------------- Commit message for microsoft/vscode-python@b0ab10d: Only use activated environment from terminal if VSCode was launched via CLI (microsoft/vscode-python#20667) Closes microsoft/vscode-python#20644 -------------------- Commit message for microsoft/vscode-python@02a92fc: Ensure interpreter path isn't truncated for workspace-relative paths when storing value (microsoft/vscode-python#20661) For microsoft/vscode-python#20660 I'm not quite sure why this was done. It doesn't make sense to do this only for display. -------------------- Commit message for microsoft/vscode-python@377067f: Use correct API to get interpreter path for language servers (microsoft/vscode-python#20656) For microsoft/vscode-python#20644 closes microsoft/vscode-python#20657 -------------------- Commit message for microsoft/vscode-python@cd6ca9d: Remove `isort` extension dependency (microsoft/vscode-python#20577) Closes microsoft/vscode-python#20586 Lead-authored-by: Kartik Raj <karraj@microsoft.com> Co-authored-by: Erik De Bonte <erikd@microsoft.com> Co-authored-by: Karthik Nadig <kanadig@microsoft.com> Co-authored-by: mitchell <mitchellb@activestate.com> Co-authored-by: Pete Farland <pete.farland@posit.co> Co-authored-by: Eleanor Boyd <eleanorboyd@microsoft.com>
Original title: Visual Studio Code doesn't select the correct Python interpreter at launch
[Kubuntu 22.04]
To fix it I have to manually select the first interpreter with the 'star' and 'Recommended' tag from the list, however it appears to be already selected (bottom right
3.10.6 ('.venv':venv)
) after launch.Steps to reproduce:
Python: Show Language Server Output:
Edit (1): Python: Report Issue...
Type: Bug
Diagnostic data
python.languageServer
setting: DefaultOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)User Settings
VS Code version: Code 1.75.0 (e2816fe719a4026ffa1ee0189dc89bdfdbafb164, 2023-02-01T15:29:17.766Z)
OS version: Linux x64 5.15.0-58-generic
Modes:
Sandboxed: No
System Info
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: disabled_software
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Extensions (12)
(3 theme extensions excluded)
A/B Experiments
Edit (2): Python Show Output
and these two lines are printed if I manually select recommended interpreter to fix the issue:
The text was updated successfully, but these errors were encountered: