vscode-python: The virtual environment doesn't exit if it's deleted

Type: Bug

Behaviour

Expected vs. Actual

I have created a virtual environment with python3 -m venv venv and the extension will automatically start the virtual environment when starting terminal.

Actual

But after I delete the venv folder, the terminal still has a leading (venv).

Expected

No leading (venv) after deleting the virtual environment like before.

Steps to reproduce:

  1. Create a virtual environment
  2. Create a python file and start a terminal.
  3. Delete the virtual environment and kill the terminal.
  4. Start a terminal, there was no venv before, but now it has.

I did all the steps on Mac with ubuntu container. I notice that it doesn’t affect everything except showing (venv) before the terminal prompt.

I have also tried in Github Codespace which has the same version of the one on my Mac. But everything works fine in CodeSpace.

Diagnostic data

  • Python version (& distribution if applicable, e.g. Anaconda):
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Unknown
  • Value of the python.languageServer setting: Default
Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

User Settings


languageServer: "Pylance"

Extension version: 2023.16.0 VS Code version: Code 1.82.2 (Universal) (abd2f3db4bdb28f9e95536dfa84d8479f1eb312d, 2023-09-14T05:59:47.790Z) OS version: Darwin x64 22.5.0 Modes: Remote OS version: Linux x64 6.3.13-linuxkit

System Info
Item Value
CPUs Intel® Core™ i7-9750H CPU @ 2.60GHz (12 x 2600)
GPU Status 2d_canvas: enabled
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
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 5, 5, 4
Memory (System) 32.00GB (0.46GB free)
Process Argv
Screen Reader no
VM 0%
Item Value
Remote Container ubuntu (kie) @ desktop-linux
OS Linux x64 6.3.13-linuxkit
CPUs Intel® Core™ i7-9750H CPU @ 2.60GHz (8 x 2592)
Memory (System) 15.63GB (13.87GB free)
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vsdfh931cf:30280410
vshan820:30294714
vstes263:30335439
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593cf:30376535
pythonvs932:30410667
py29gd2263:30792226
vscaac:30438847
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30695312
azure-dev_surveyone:30548225
2e4cg342:30602488
f6dab269:30613381
2i9eh265:30646982
showlangstatbar:30737416
962ge761:30841074
03d35959:30757346
pythonfmttext:30731395
fixshowwlkth:30771522
showindicator:30805244
pythongtdpath:30769146
i26e3531:30792625
pythonnosmt12:30797651
pythonidxptcf:30805731
pythonnoceb:30805159
copilotsettingc:30839828
synctok:30821570
dsvsc013:30795093
dsvsc014:30804076
diffeditorv2:30821572
dsvsc015cf:30829746

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

Gotcha, actually each OS has a different VS Code file watcher, so I’m not surprised that the behavior is different. rm -rf venv seems like a good enough solution for Mac then.

Happy coding!

VS Code fails to inform us if folder has been directly deleted due to a limitation on their end: https://github.com/microsoft/vscode/issues/110923. However, if you could just run the rm .venv/bin/python, we should now be able to detect it and reset terminals.

Thanks for the log, I’m able to confirm the issue. It’s actually a limitation imposed by caching. Running Developer: Reload Window after deletion and then creating a new terminal should make the (.venv) prompt is go away.