Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Ashcora opened this issue Dec 18, 2024 · 2 comments
Closed

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

Ashcora opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@Ashcora
Copy link

Ashcora commented Dec 18, 2024

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
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Dec 18, 2024
@karthiknadig
Copy link
Member

Can you try disabling the following experiment?

"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]

You will have to reload VS Code to get state to revert.

@karthiknadig karthiknadig self-assigned this Dec 19, 2024
@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Dec 19, 2024
@Ashcora
Copy link
Author

Ashcora commented Dec 19, 2024

@karthiknadig : Thank you for your prompt support. It seems to have solved my issue. After setting this parameter in the workspace settings and reloading VS Code, it now opens with the (venv) activated, even in the previously open terminals. Closing them and clicking the Play button also results in the desired situation.

Image

@Ashcora Ashcora closed this as completed Dec 19, 2024
@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants