Skip to content

Python venv not automatically activating when clicking the Play button #24639

@tobschndr

Description

@tobschndr

Type: Bug

Description: When running a Python script in VS Code, the virtual environment (venv) is not automatically activated, even though the interpreter is correctly selected. In the lower window, I see the interpreter "3.12.8 ('.venv': venv)", but when clicking the Play button, the venv is not activated (it does not appear in green as (venv) in the terminal).

Steps to Reproduce:

  1. Create a new project in VS Code.
  2. Create a virtual environment (venv) with python -m venv .venv.
  3. Select the interpreter "3.12.8 ('.venv': venv)".
  4. Open a Python script and click the Play button.

Expected Behavior:
The terminal should automatically activate the virtual environment (venv), and "(venv)" should appear in green in the terminal.

Actual Behavior:
The terminal does not automatically activate the virtual environment (venv), and "(venv)" does not appear in the terminal.
BUT: There is a hint shown by VS Code that it is activated even when not showing.
Image
BUT: when then running a script, use the same terminal to install a pip package...it will be installed to the global environment, not to the "activated" venv

Additional Configuration Done:

  1. Go to File > Preferences and search for Terminal > Integrated: Enable Persistent Settings. Ensure this option is enabled.
  2. Search for Python > Terminal: Activate Environment in Current Terminal and ensure this option is enabled.
  3. Search for Python > Terminal: Activate Environment (in all terminals) and ensure this option is enabled

Extension version: 2024.23.2024121801
VS Code version: Code 1.96.0 (138f619c86f1199955d53b4166bef66ef252935c, 2024-12-11T02:29:09.626Z)
OS version: Windows_NT x64 10.0.22631
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.8
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

terminal
• executeInFileDir: "<placeholder>"

Installed Extensions
Extension Name Extension Id Version
black-formatter ms- 2024.5.13171011
copilot Git 1.252.1270
copilot-chat Git 0.23.2024102903
debugpy ms- 2024.15.2024121701
js-debug ms- 1.96.0
js-debug-companion ms- 1.1.3
json Zai 2.0.2
jupyter ms- 2025.1.2024121801
jupyter-keymap ms- 1.1.2
powershell ms- 2024.4.0
python ms- 2024.23.2024121801
python-environment-manager don 1.2.4
vscode-js-profile-table ms- 1.0.10
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
vscode-language-pack-de MS- 1.96.2024121109
vscode-pylance ms- 2024.12.100
vscode-xml red 0.27.2024121308
vscode-yaml red 1.15.0
vscodeintellicode Vis 1.3.2

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugtriage-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