microsoft / vscode-python

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

Activate Environment activates even in REPLs from other languages #23947

Open toihr opened 1 month ago

toihr commented 1 month ago

Type: Bug

Behaviour

When having the Activate Environments setting checked, the Python extension tries to activate in REPLs from other Languages i.e. Julia REPL, which is a problem as conda activate .... is not a valid Julia Code.

Steps to reproduce:

  1. Install Python Extension
  2. Install Julia Extension

When wanting to execute a Julia Script "Julia Execute Active File in REPL" the conda activate ... line is always, sometimes even twice.

Diagnostic data

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

``` 2024-08-14 15:33:34.399 [info] Not enabling terminal env var experiment in multiroot remote workspaces 2024-08-14 15:33:34.477 [info] > conda info --json 2024-08-14 15:33:35.711 [info] Send text to terminal: conda activate planetary 2024-08-14 15:34:00.156 [info] Python interpreter path: /bin/python3 ```

Extension version: 2024.12.3 VS Code version: Code 1.92.1 (eaa41d57266683296de7d118f574d0c2652e1fc4, 2024-08-07T20:16:39.455Z) OS version: Windows_NT x64 10.0.22635 Modes: Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2

User Settings

``` Multiroot scenario, following user settings may not apply: languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |autoDocstring - Python Docstring Generator|njpwerner.autodocstring|0.6.1| |autopep8|ms-python.autopep8|2024.0.0| |GitHub Copilot|GitHub.copilot|1.221.0| |GitHub Copilot Chat|GitHub.copilot-chat|0.18.1| |GitLens — Git supercharged|eamodio.gitlens|15.2.3| |isort|ms-python.isort|2023.10.1| |JavaScript Debugger|ms-vscode.js-debug|1.92.0| |Julia|julialang.language-julia|1.105.2| |Jupyter|ms-toolsai.jupyter|2024.7.0| |Jupyter Cell Tags|ms-toolsai.vscode-jupyter-cell-tags|0.1.9| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.19| |Jupyter Slide Show|ms-toolsai.vscode-jupyter-slideshow|0.1.6| |Live Server|ritwickdey.LiveServer|5.7.9| |Live Share|ms-vsliveshare.vsliveshare|1.0.5936| |Path Intellisense|christian-kohler.path-intellisense|2.9.0| |Pylance|ms-python.vscode-pylance|2024.8.1| |Pylint|ms-python.pylint|2023.10.1| |Python|ms-python.python|2024.12.2| |Python Debugger|ms-python.debugpy|2024.10.0| |Rainbow CSV|mechatroner.rainbow-csv|3.12.0| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9| |TabOut|albert.TabOut|0.2.2| |Todo Tree|Gruntfuggly.todo-tree|0.0.226|
System Info |Item|Value| |---|---| |CPUs|13th Gen Intel(R) Core(TM) i9-13900H (20 x 2995)| |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
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off| |Load (avg)|undefined| |Memory (System)|39.64GB (10.25GB free)| |Process Argv|--crash-reporter-id f5543582-acb8-470c-994d-dac2d25eca4a| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|WSL: Ubuntu2| |OS|Linux x64 5.15.153.1-microsoft-standard-WSL2| |CPUs|13th Gen Intel(R) Core(TM) i9-13900H (20 x 0)| |Memory (System)|24.46GB (13.23GB free)| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492cf:30256860 vscod805:30301674 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialogc:30910334 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 dsvsc021:30996838 g316j359:31013175 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupytercf:31046870 impr_priority:31102340 refactort:31108082 pythonrstrctxt:31112756 wkspc-onlycs-t:31111718 wkspc-ranged-t:31111713 ```
anthonykim1 commented 3 weeks ago

Hello @toihr Thank you for filing the issue here. When you say you have the activate environment setting checked, are you referring to the very first one in the screenshot?: Screenshot 2024-08-23 at 10 54 03 AM

toihr commented 2 weeks ago

@anthonykim1, yes i have Activate Environment in all Terminals created checked. I understand that this kinda means that it will activate on all Terminals. But the problem is if its not activated the environment never activates, and if I have it activated it interjects into my Julia Terminal.

This behaviour is mentioned in https://github.com/julia-vscode/julia-vscode/issues/1901 which discuesses this, even though it fails to find a solution on the Julia side.

An alternative solution would be if I could specify a batch script to run before the python run commands that just contain conda activate environment_name.

anthonykim1 commented 2 weeks ago

I think the workaround that was mentioned in the referenced issue is adding: https://github.com/julia-vscode/julia-vscode/issues/1901#issuecomment-1407202107

I'm curious to investigate more on this: When your terminal activates, do you ever see the line of command that is the actual activate script?

Also, one more thing: Does adding "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]," in your settings.json cause any change?

Make sure to "Python Clear Cache and Reload" after you have added any new settings.