microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.34k stars 1.19k forks source link

Terminal does not activate my ".conda" environment that is selected as "Current Interpreter" #24472

Open jpfeuffer opened 5 days ago

jpfeuffer commented 5 days ago

Type: Bug

Behaviour

When I open a new zsh terminal in VSCode, although I activated "activateActiveEnvironmentInTerminal" (or how this settings is called), it only loads the conda base environment. My .conda environment in the same folder is correctly selected and displayed in the lower right corner of VSCode. And I can activate it easily with conda activate ./.conda

Steps to reproduce:

  1. Activate "activateActiveEnvironmentInTerminal" in settings
  2. Select interpreter
  3. New environment
  4. Select .conda
  5. Create it
  6. Open a new Terminal and hope it gets activated.

The problem is that you command tried to run conda -n .conda and not conda -p .conda. This is a PREFIX environment not a NAMED environment..

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` 2024-11-21 13:05:03.417 [error] getActivatedEnvironmentVariables Error: Command failed: conda run -n .conda --no-capture-output python /Users/x/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/x/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py EnvironmentLocationNotFound: Not a conda environment: /Users/x/miniforge3/envs/.conda at genericNodeError (node:internal/errors:984:15) at wrappedFn (node:internal/errors:538:14) at ChildProcess.exithandler (node:child_process:423:12) at ChildProcess.emit (node:events:531:35) at maybeClose (node:internal/child_process:1105:16) at Socket. (node:internal/child_process:457:11) at Socket.emit (node:events:519:28) at Pipe. (node:net:339:12) { code: 1, killed: false, signal: null, cmd: 'conda run -n .conda --no-capture-output python /Users/x/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/get_output_via_markers.py /Users/x/.vscode/extensions/ms-python.python-2024.20.0-darwin-arm64/python_files/printEnvVariables.py' } ```

Extension version: 2024.20.0 VS Code version: Code 1.95.3 (Universal) (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z) OS version: Darwin arm64 23.6.0 Modes:

User Settings

``` venvPath: "" languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |Actionforge Graph Editor|Actionforge.actionforge|0.9.84| |autoDocstring - Python Docstring Generator|njpwerner.autodocstring|0.6.1| |Better C++ Syntax|jeff-hykin.better-cpp-syntax|1.27.1| |Black Formatter|ms-python.black-formatter|2024.4.0| |Browse Lite|antfu.browse-lite|0.3.9| |C/C++|ms-vscode.cpptools|1.22.11| |C/C++ Extension Pack|ms-vscode.cpptools-extension-pack|1.3.0| |C/C++ Themes|ms-vscode.cpptools-themes|2.0.0| |carbon-now-sh|ericadamski.carbon-now-sh|1.2.0| |clangd|llvm-vs-code-extensions.vscode-clangd|0.1.31| |CMake|twxs.cmake|0.0.17| |CMake Test Explorer|fredericbonnet.cmake-test-adapter|0.17.4| |CMake Tools|ms-vscode.cmake-tools|1.19.52| |cmake-format|cheshirekow.cmake-format|0.6.11| |CodeLLDB|vadimcn.vscode-lldb|1.11.1| |CodeWhisperer for command line|amazonwebservices.codewhisperer-for-command-line-companion|0.1.0| |Data Wrangler|ms-toolsai.datawrangler|1.12.1| |Dev Containers|ms-vscode-remote.remote-containers|0.388.0| |Docker|ms-azuretools.vscode-docker|1.29.3| |Doxygen Documentation Generator|cschlosser.doxdocgen|1.4.0| |Even Better TOML|tamasfe.even-better-toml|0.19.2| |Flake8|ms-python.flake8|2023.10.0| |GitHub Actions|github.vscode-github-actions|0.27.0| |GitHub Copilot|GitHub.copilot|1.245.1221| |GitHub Copilot Chat|GitHub.copilot-chat|0.23.2024102903| |GitHub Markdown Preview|bierner.github-markdown-preview|0.3.0| |Gitpod|gitpod.gitpod-desktop|0.0.180| |HashiCorp Terraform|hashicorp.terraform|2.34.0| |HTML CSS Support|ecmel.vscode-html-css|2.0.11| |isort|ms-python.isort|2023.10.1| |JavaScript Debugger|ms-vscode.js-debug|1.95.3| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.3| |Jupyter|ms-toolsai.jupyter|2024.10.0| |Jupyter Keymap|ms-toolsai.jupyter-keymap|1.1.2| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.21| |Just pilot|lrh3321.just2|2.0.2| |Learn Vim|vintharas.learn-vim|0.0.28| |Markdown Checkboxes|bierner.markdown-checkbox|0.4.0| |Markdown Emoji|bierner.markdown-emoji|0.3.0| |Markdown Footnotes|bierner.markdown-footnotes|0.1.1| |Markdown Preview for Github Alerts|yahyabatulu.vscode-markdown-alert|0.0.4| |Markdown Preview Github Styling|bierner.markdown-preview-github-styles|2.1.0| |Markdown Preview Mermaid Support|bierner.markdown-mermaid|1.27.0| |Markdown yaml Preamble|bierner.markdown-yaml-preamble|0.1.0| |markdownlint|DavidAnson.vscode-markdownlint|0.57.0| |Mojo 🔥|modular-mojotools.vscode-mojo|24.5.5| |New Syntax Highlighter|fallenwood.syntax-highlighter-ng|0.6.0| |Nextflow|nextflow.nextflow|1.0.1| |Open in GitHub|fabiospampinato.vscode-open-in-github|2.3.0| |Pylance|ms-python.vscode-pylance|2024.11.2| |Python|ms-python.python|2024.20.0| |Python Debugger|ms-python.debugpy|2024.12.0| |Python Envy|teticio.python-envy|0.1.8| |Python Sphinx Highlighter|leonhard-s.python-sphinx-highlight|0.3.0| |Rainbow CSV|mechatroner.rainbow-csv|3.12.0| |Remote - SSH|ms-vscode-remote.remote-ssh|0.115.1| |Remote - SSH: Editing Configuration Files|ms-vscode-remote.remote-ssh-edit|0.87.0| |Remote Development|ms-vscode-remote.vscode-remote-extensionpack|0.26.0| |rust|1YiB.rust-bundle|1.0.0| |Rust Syntax|dustypomerleau.rust-syntax|0.6.1| |rust-analyzer|rust-lang.rust-analyzer|0.3.2188| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.10| |Test Adapter Converter|ms-vscode.test-adapter-converter|0.2.1| |Test Explorer UI|hbenl.vscode-test-explorer|2.22.1| |Trusty Rusty Snippets|polypus74.trusty-rusty-snippets|0.0.5| |Vim|vscodevim.vim|1.28.1| |Vite|antfu.vite|0.2.5| |WSL|ms-vscode-remote.remote-wsl|0.88.5| |yapf|eeyore.yapf|2024.9.126091437|
System Info |Item|Value| |---|---| |CPUs|Apple M2 Max (12 x 2400)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
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_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|2, 3, 3| |Memory (System)|64.00GB (19.55GB free)| |Process Argv|--crash-reporter-id 6ff5cf85-0c6d-49ba-b87f-c0bb6780000d| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythonnoceb:30805159 asynctok:30898717 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 jg8ic977:31013176 dvdeprecation:31068756 dwnewjupyter:31046869 nativerepl1:31139838 pythonrstrctxt:31112756 cf971741:31144450 iacca1:31171482 notype1cf:31157160 5fd0e150:31155592 dwcopilot:31170013 stablechunks:31184530 ```
karthiknadig commented 1 day ago

@jpfeuffer Can you share the exact setting you are using (i.e., can you share the settings.json content)? Python extension only has the following settings for activation: python.terminal.activateEnvInCurrentTerminal python.terminal.activateEnvironment

We detect prefixed vs named environments, so it should use the correct command.

jpfeuffer commented 1 day ago

Now it doesn't even try to find my environment anymore. I don't get any logs of your extension trying to set my .conda environment...

My only python settings are:

"python.venvPath": "....../pypoetry/virtualenvs", "python.analysis.typeCheckingMode": "basic",

python.terminal.activateEnvInCurrentTerminal is ON by default as far as I can see.

jpfeuffer commented 1 day ago

I tried with and without python.terminal.activateEnvInCurrentTerminal. Both do not work.

jpfeuffer commented 1 day ago

Ok, so with python locator = js it just does nothing. With python locator = native I get the error from my initial report.

In summary: nothing works.

jpfeuffer commented 1 day ago

You do detect prefixed environments for stuff like pylance, but not for activation in the shell.

cividis commented 15 hours ago

I encountered the same issue too, which only started occurring for me this morning.

When I open a new terminal, I have to manually activate the environment with conda activate ./.conda. When I run the current line or file, it does use the .conda/bin/python, however.

My settings.json is as follows:

{
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true
    },
    "terminal.integrated.inheritEnv": false,
    "editor.minimap.enabled": false,
    "python.terminal.activateEnvInCurrentTerminal": true, // just added, but no effect
    "python.terminal.activateEnvironment": true // just added, but no effect
}
karthiknadig commented 6 hours ago

Can you try version 2024.16.1 or 2024.14.1 and see if they behave better? This will help narrow down the problem. Locally I am not able to repo this. You can switch version using the ⚙️icon from the extension view and selecting "install specific version": Image