Skip to content

Terminal no longer activates virtual environment for csh/tcsh shell #22822

Closed as not planned

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:

  1. Create a python virtual environment.
  2. Modify the activate script
  3. select the virtual environment from thepython version dropdown in VS Code
  4. 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.languageServer setting: 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

  1. rhizodigital commented on Feb 1, 2024

    @rhizodigital

    Yes I can confirm this exact same problem.

  2. karrtikr commented on Feb 1, 2024

    @karrtikr

    Austin Witherspoon (@austinwitherspoon) Can you please provide the debug logs which can help diagnose the issue:

    • Run Developer: Set log level command
    • Select Trace
    • Run Developer: Reload Window command
    • Provide the output:
    Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

    XXX
    

    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.

    but none of the environment is actually being configured in the terminal. All environment variables and aliases are absent.

    Could you send a screenshot of env variables and aliases that're expected?

  3. karrtikr commented on Feb 1, 2024

    @karrtikr

    I'm wondering if it's a csh shell issue. Could you try changing the default shell (Select default profile command) to bash/zsh/fish and see if the issue happens?

  4. invas3 commented on Feb 1, 2024

    @invas3

    I have same problems and I use vscode on windows 10

  5. austinwitherspoon commented on Feb 1, 2024

    @austinwitherspoon
    Author

    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 which command to see where python points.
    In the VS Code terminal by default, python doesn't point to the virtual environment python, it points to my system python:
    image

    However, if I run source venv/bin/activate.csh and then try:
    image
    It points at the correct python in the virtual environment

    So clearly source venv/bin/activate.csh is not running (which is used to automatically every time you opened a new terminal window!)

  6. austinwitherspoon commented on Feb 1, 2024

    @austinwitherspoon
    Author

    I'm wondering if it's a csh shell issue. Could you try changing the default shell (Select default profile command) to bash/zsh/fish and see if the issue happens?

    Interesting! Switching my default terminal to bash works fine!
    tcsh and csh both don't work, but bash works.

  7. changed the title [-]Terminal no longer activates virtual environment [/-] [+]Terminal no longer activates virtual environment for csh/tcsh shell[/+] on Feb 1, 2024
  8. karrtikr commented on Feb 1, 2024

    @karrtikr

    Great, let me try to install csh and reproduce the issue. Do you have some instructions handy?

  9. austinwitherspoon commented on Feb 1, 2024

    @austinwitherspoon
    Author

    Great, let me try to install csh and reproduce the issue. Do you have some instructions handy?

    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

  10. 54 remaining items

  11. karrtikr commented on Feb 14, 2024

    @karrtikr

    "/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 the PATH, which seems to be in the middle. Can you investigate where rest of the stuff is being prepended from, if not .tcshrc?

    /Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:./node_modules/.bin:/Users/awitherspoon/node_modules/.bin:/Users/awitherspoon/bin:/Users/awitherspoon/src/studio/prod-tools/sbin:/Users/awitherspoon/src/studio/prod-tools/sbin/shotgun:none/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/bin:/Applications/IntelliJIDEA.app/bin:none/bin:/Users/awitherspoon/.local/bin
    
  12. austinwitherspoon commented on Feb 14, 2024

    @austinwitherspoon
    Author

    I found a corporate csh.cshrc on 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:/sbin

    With that change, which python works, but that still doesn't fix the fact that environment variables from activate.csh are not being loaded in like they used to in v2023.4.1

  13. austinwitherspoon commented on Feb 14, 2024

    @austinwitherspoon
    Author

    Actually this problem applies to all shells (not just csh), bash and zsh work with which python but 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?

  14. karrtikr commented on Feb 27, 2024

    @karrtikr

    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 using Python: Report Issue command, include the "debug" level logs and we'll be happy to have a look.

    Closing as current behavior for now.

  15. kyrlon commented on Feb 29, 2024

    @kyrlon

    I have same problems and I use vscode on windows 10

    Same issue with activating with git bash, powershell, and command prompt

  16. karrtikr commented on Feb 29, 2024

    @karrtikr

    Please create a new issue for Powershell and we can have a look. Make sure to provide the "debug" level logs asked earlier.

  17. kyrlon commented on Mar 1, 2024

    @kyrlon

    Please create a new issue for Powershell and we can have a look. Make sure to provide the "debug" level logs asked earlier.

    #23008

  18. michaelleb commented on Mar 9, 2024

    @michaelleb

    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.

  19. added 2 commits that reference this issue on Mar 28, 2024
  20. locked as resolved and limited conversation to collaborators on Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalbugIssue identified by VS Code Team member as probable bugexperimentingFeature is part of an experimentinfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions