Repository navigation
Terminal no longer activates virtual environment for csh/tcsh shell #22822
Description
Type: Bug
Behaviour
Expected vs. Actual
At work, we've been using VS Code for a while with python virtual environments. The previous behavior was that when you opened a terminal (while a virtual environment was activated) it would run the activate script in that virtual environment. For example for me, usually venv/bin/activate.csh. This script has become an important part of our workflow, since it allows us to customize the environment python will run in, register aliases, etc.
Ever since a few months ago, VS code no longer runs this activation script. It says "Python virtual environment was successfully activated, even though "(venv)" indicator may not be present in the terminal prompt.", Which seems to indicate that it is triggering the virtual environment, but none of the environment is actually being configured in the terminal. All environment variables and aliases are absent.
Steps to reproduce:
- Create a python virtual environment.
- Modify the activate script
- select the virtual environment from thepython version dropdown in VS Code
- Open a terminal
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.11.4
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the
python.languageServersetting: Pylance
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
XXX
User Settings
languageServer: "Pylance"
testing
• pytestEnabled: true
Extension version: 2023.22.1
VS Code version: Code 1.85.2 (Universal) (8b3775030ed1a69b13e4f4c628c612102e30a681, 2024-01-18T06:40:32.531Z)
OS version: Darwin arm64 22.6.0
Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Apple M1 Max (10 x 24) |
| 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 video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled |
| Load (avg) | 3, 2, 2 |
| Memory (System) | 32.00GB (0.08GB free) |
| Process Argv | --crash-reporter-id 00815bc4-2696-4c23-866e-19b398c1bc9b |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscoreces:30445986
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30951796
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
pythontbext0:30879054
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
dsvsc019bcf:30953938
3ef8e399:30949928
Activity
rhizodigital commentedon Feb 1, 2024
Yes I can confirm this exact same problem.
karrtikr commentedon Feb 1, 2024
Austin Witherspoon (@austinwitherspoon) Can you please provide the debug logs which can help diagnose the issue:
Developer: Set log levelcommandTraceDeveloper: Reload WindowcommandOutput for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)Expected behavior to have the virtual environment activated using environment variables, without running any commands. More information: https://github.com/microsoft/vscode-python/wiki/Activate-Environments-in-Terminal-Using-Environment-Variables.
Could you send a screenshot of env variables and aliases that're expected?
karrtikr commentedon Feb 1, 2024
I'm wondering if it's a csh shell issue. Could you try changing the default shell (
Select default profilecommand) to bash/zsh/fish and see if the issue happens?invas3 commentedon Feb 1, 2024
I have same problems and I use vscode on windows 10
austinwitherspoon commentedon Feb 1, 2024
awitherspoon_vscode_python_trace_log.txt
Here's the trace log you requested (with some sensitive keywords and environment variables redacted)
The easiest way to see that it's not working is actually just by using the

whichcommand to see where python points.In the VS Code terminal by default,
pythondoesn't point to the virtual environment python, it points to my system python:However, if I run

source venv/bin/activate.cshand then try:It points at the correct python in the virtual environment
So clearly
source venv/bin/activate.cshis not running (which is used to automatically every time you opened a new terminal window!)austinwitherspoon commentedon Feb 1, 2024
Interesting! Switching my default terminal to bash works fine!
tcsh and csh both don't work, but bash works.
[-]Terminal no longer activates virtual environment [/-][+]Terminal no longer activates virtual environment for csh/tcsh shell[/+]karrtikr commentedon Feb 1, 2024
Great, let me try to install csh and reproduce the issue. Do you have some instructions handy?
austinwitherspoon commentedon Feb 1, 2024
Unfortunately no, it came on my work computer and I'm usually a windows guy, so I'm not super familiar with linux/mac shells
54 remaining items
karrtikr commentedon Feb 14, 2024
"/Users/awitherspoon/.vscode/extensions/ms-python.python-2024.1.10451007/pythonFiles/deactivate/bash:/Users/awitherspoon/src/personal/examplevenv/venv/bin"is what we expect to be at front of thePATH, which seems to be in the middle. Can you investigate where rest of the stuff is being prepended from, if not.tcshrc?austinwitherspoon commentedon Feb 14, 2024
I found a corporate
csh.cshrcon my machine that added those vars. If I go in and temporarily remove it, I get the following:/Users/awitherspoon/.vscode/extensions/ms-python.python-2024.1.10451007/pythonFiles/deactivate/bash:/Users/awitherspoon/src/personal/examplevenv/venv/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/bin:/bin:/usr/sbin:/sbinWith that change,
which pythonworks, but that still doesn't fix the fact that environment variables fromactivate.cshare not being loaded in like they used to inv2023.4.1austinwitherspoon commentedon Feb 14, 2024
Actually this problem applies to all shells (not just csh), bash and zsh work with
which pythonbut do not actually contain the environment variables from the activate scripts like they used to.It looks like the plugin isn't actually loading the environment, it's only modifying PATH?
karrtikr commentedon Feb 27, 2024
Thanks for all the notes, we'll keep it in mind if more users encounter the error related to csh shell where they have to rely on
activate.csh.If you still face an issue while you have selected "bash" or "zsh" as default shell, and it seems it does not load all the environment variables in addition to
PATH, please feel free to open a new issue usingPython: Report Issuecommand, include the "debug" level logs and we'll be happy to have a look.Closing as current behavior for now.
kyrlon commentedon Feb 29, 2024
Same issue with activating with git bash, powershell, and command prompt
karrtikr commentedon Feb 29, 2024
Please create a new issue for Powershell and we can have a look. Make sure to provide the "debug" level logs asked earlier.
kyrlon commentedon Mar 1, 2024
#23008
michaelleb commentedon Mar 9, 2024
Got the same issue with vs code v 1.87.1 universal on mac os 14.4 Sonoma, zsh terminal.
Fresh installation of VsCode on new MacBook.
Issue: the integrated terminal failed to load Python environment.
Solved by reinstallation of vscode.
more details: after removing the first installation of the 1.87.1 universal, I installed the silicon 1.87.1 version, and found out that the issue is gone. Then, I installed again the universal version, but couldn't reproduce the issue there.
Merged PR posit-dev/positron-python#395: Merge upstream: `v2024.2.0`
Merged PR posit-dev/positron-python#395: Merge upstream: `v2024.2.0`