Registryvsx-ms-pythonvscode-python-envs

@vsx-ms-python/vscode-python-envs

Public
VSX CompatibleOXP Native: Planned

// Description

Provides a unified python environment experience

// Readme

Open VSX

#Python Environments (preview)

Note: The Python Environments icon may no longer appear in the Activity Bar due to the ongoing rollout of the Python Environments extension. To restore the extension, add "python.useEnvironmentsExtension": true to your User settings. This setting is temporarily necessary until the rollout is complete!

##Overview

The Python Environments extension for VS Code helps you manage Python environments and packages using your preferred environment manager, backed by its extensible APIs. This extension provides unique support for specifying environments for specific files, entire Python folders, or projects, including multi-root and mono-repo scenarios. The core feature set includes:

  • 🌐 Create, delete, and manage environments
  • 📦 Install and uninstall packages within the selected environment
  • ✅ Create activated terminals
  • 🖌️ Add and create new Python projects

Note: This extension is in preview, and its APIs and features are subject to change as the project evolves.

Important: This extension requires version 2024.23, or later, of the Python extension (ms-python.python).

##Features

The "Python Projects" fold shows you all of the projects that are currently in your workspace and their selected environments. From this view you can add more files or folders as projects, select a new environment for your project, and manage your selected environments.

The "Environment Managers" fold shows you all of the environment managers that are available on your machine with all related environments nested below. From this view, you can create new environments, delete old environments, and manage packages.

###Environment Management

The Python Environments panel provides an interface to create, delete and manage environments.

To simplify the environment creation process, you can use "Quick Create" to automatically create a new virtual environment using:

  • Your default environment manager (e.g., venv)
  • The latest Python version
  • Workspace dependencies

For more control, you can create a custom environment where you can specify Python version, environment name, packages to be installed, and more!

The following environment managers are supported out of the box:

IdNameDescription
ms-python.python:venvvenvBuilt-in environment manager provided by the Python standard library. Supports creating environments (interactive and quick create) and finding existing environments.
ms-python.python:systemSystem Installed PythonGlobal Python installs on your system, typically installed with your OS, from python.org, or any other OS package manager.
ms-python.python:condacondaThe conda environment manager, as provided by conda distributions like Anaconda Distribution or conda-forge. Supports creating environments (interactive and quick create) and finding existing environments.
ms-python.python:pyenvpyenvThe pyenv environment manager, used to manage multiple Python versions. Supports finding existing environments.
ms-python.python:poetrypoetryThe poetry environment manager, used for dependency management and packaging in Python projects. Supports finding existing environments.
ms-python.python:pipenvpipenvThe pipenv environment manager, used for managing Python dependencies and environments. Only supports finding existing environments.

Supported Actions by Environment Manager

Environment ManagerFind EnvironmentsCreateQuick Create
venv
conda
pyenv
poetry
system
pipenv

Legend:

  • Create: Ability to create new environments interactively.
  • Quick Create: Ability to create environments with minimal user input.
  • Find Environments: Ability to discover and list existing environments.

Environment managers are responsible for specifying which package manager will be used by default to install and manage Python packages within the environment (venv uses pip by default). This ensures that packages are managed consistently according to the preferred tools and settings of the chosen environment manager.

###Package Management

The extension also provides an interface to install and uninstall Python packages, and provides APIs for extension developers to contribute package managers of their choice.

The extension uses pip as the default package manager, but you can use the package manager of your choice using the python-envs.defaultPackageManager setting. The following are package managers supported out of the box:

IdNameDescription
ms-python.python:pippipPip acts as the default package manager and it's typically built-in to Python.
ms-python.python:condacondaThe conda package manager, as provided by conda distributions like Anaconda Distribution or conda-forge.

Default Package Manager by Environment Manager

Environment ManagerDefault Package Manager
venvpip
condaconda
pyenvpip
poetrypoetry
systempip
pipenvpip

###Project Management

A "Python Project" is any file or folder that contains runnable Python code and needs its own environment. With the Python Environments extension, you can add files and folders as projects in your workspace and assign individual environments to them allowing you to run various projects more seamlessly.

Projects can be added via the Python Environments pane or in the File Explorer by right-clicking on the folder/file and selecting the "Add as Python Project" menu item.

There are a few ways to add a Python Project from the Python Environments panel:

NameDescription
Add ExistingAllows you to add an existing folder from the file explorer.
Auto findSearches for folders that contain pyproject.toml or setup.py files
Create NewCreates a new project from a template.

Create New Project from Template

The Python Envs: Create New Project from Template command simplifies the process of starting a new Python project by scaffolding it for you. Whether in a new workspace or an existing one, this command configures the environment and boilerplate file structure, so you don’t have to worry about the initial setup, and only the code you want to write. There are currently two project types supported:

  • Package: A structured Python package with files like __init__.py and setup configurations.
  • Script: A simple project for standalone Python scripts, ideal for quick tasks or just to get you started.

##Command Reference

All commands can be accessed via the Command Palette (ctrl/cmd + Shift + P):

NameDescription
Create EnvironmentCreate a virtual environment using your preferred environment manager preconfigured with "Quick Create" or configured to your choices.
Manage PackagesInstall and uninstall packages in a given Python environment.
Activate Environment in Current TerminalActivates the currently opened terminal with a particular environment.
Deactivate Environment in Current TerminalDeactivates environment in currently opened terminal.
Run as TaskRuns Python module as a task.
Create New Project from TemplateCreates scaffolded project with virtual environments based on a template.

##Settings Reference

###Python Environments Settings (python-envs.)

Setting (python-envs.)DefaultDescription
defaultEnvManager"ms-python.python:venv"The default environment manager used for creating and managing environments.
defaultPackageManager"ms-python.python:pip"The default package manager to use for installing and managing packages. This is often dictated by the default environment manager but can be customized.
pythonProjects[]A list of Python workspaces, specified by the path, in which you can set particular environment and package managers. You can set information for a workspace as [{"path": "/path/to/workspace", "envManager": "ms-python.python:venv", "packageManager": "ms-python.python:pip"]}.
terminal.showActivateButtonfalse(experimental) Show a button in the terminal to activate/deactivate the current environment for the terminal. This button is only shown if the active terminal is associated with a project that has an activatable environment.
terminal.autoActivationType"command"Specifies how the extension can activate an environment in a terminal. Accepted values: command (execute activation command in terminal), shellStartup (terminal.integrated.shellIntegration.enabled successfully enabled or we may modify shell startup scripts ), off (no auto-activation). Shell startup is only supported for: zsh, fish, pwsh, bash, cmd. Takes precedence over python.terminal.activateEnvironment. Restart terminals after changing this setting. To revert shell startup changes, run Python Envs: Revert Shell Startup Script Changes.
alwaysUseUvtrueWhen true, uv will be used to manage all virtual environments if available. When false, uv will only manage virtual environments explicitly created by uv.
globalSearchPaths[]Global search paths for Python environments. Array of absolute directory paths to search for environments at the user level. This setting is merged with the legacy python.venvPath and python.venvFolders settings.
workspaceSearchPaths[]Workspace search paths for Python environments. Can be absolute paths or relative directory paths searched within the workspace.

###Supported Legacy Python Settings (python.)

The following settings from the Python extension (python.*) are also supported by Python Environments.

Setting (python.)DefaultDescription
condaPath""Path to the conda executable. Used to locate and run conda for environment discovery and management.
defaultInterpreterPath"python"Path to the default Python interpreter.
envFile"${workspaceFolder}/.env"Path to the environment file (.env) containing environment variable definitions. Used with python.terminal.useEnvFile to inject environment variables into terminals.
terminal.activateEnvironmenttrueLegacy setting for terminal auto-activation. If python-envs.terminal.autoActivationType is not set and this is false, terminal auto-activation will be disabled. Superseded by python-envs.terminal.autoActivationType which takes precedence when configured.
terminal.executeInFileDirfalseWhen true, the terminal's working directory will be set to the directory containing the Python file being executed, rather than the project root directory.
terminal.useEnvFilefalseControls whether environment variables from .env files (specified by python.envFile) are injected into terminals.
venvFolders[]Array of folder names to search for virtual environments. These folders are searched in addition to the standard locations. Note: This setting is merged with python-envs.globalSearchPaths. Consider migrating to python-envs.globalSearchPaths for future compatibility.
venvPath""Path to a folder containing virtual environments. Note: This setting is merged with python-envs.globalSearchPaths. Consider migrating to python-envs.globalSearchPaths for future compatibility.

##Extensibility

The Python Environments extension was built to provide a cohesive and user friendly experience with venv as the default. However, the extension is built with extensibility in mind so that any environment manager could build an extension using the supported APIs to plug-in and provide a seamless and incorporated experience for their users in VS Code.

###API Reference (proposed)

See api.ts for the full list of Extension APIs.

To consume these APIs you can look at the example here: API Consumption Examples

###Callable Commands

The extension provides a set of callable commands that can be used to interact with the environment and package managers. These commands can be invoked from other extensions or from the command palette.

python-envs.createAny

Create a new environment using any of the available environment managers. This command will prompt the user to select the environment manager to use. Following options are available on this command:

{
    /**
     * Default `false`. If `true` the creation provider should show back button when showing QuickPick or QuickInput.
     */
    showBackButton?: boolean;

    /**
     * Default `true`. If `true`, the environment after creation will be selected.
     */
    selectEnvironment?: boolean;

    /**
     * Provides some context about quick create based on user input.
     *   - if true, the environment should be created without any user input or prompts.
     *   - if false, the environment creation can show user input or prompts.
     *     This also means user explicitly skipped the quick create option.
     *   - if undefined, the environment creation can show user input or prompts.
     *     You can show quick create option to the user if you support it.
     */
    quickCreate?: boolean;
    /**
     * Packages to install in addition to the automatically picked packages as a part of creating environment.
     */
    additionalPackages?: string[];
}

usage: await vscode.commands.executeCommand('python-envs.createAny', options);

#Experimental Features

##Shell Startup Activation

The Python Environments extension supports shell startup activation for environments. This feature allows you to automatically activate a Python environment when you open a terminal in VS Code. The activation is done by modifying the shell's startup script, which is supported for the following shells:

  • Bash: ~/.bashrc
  • Zsh: ~/.zshrc (or $ZDOTDIR/.zshrc if ZDOTDIR is set)
  • Fish: ~/.config/fish/config.fish
  • PowerShell:
    • (Mac/Linux):~/.config/powershell/profile.ps1
    • (Windows): ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
  • CMD: ~/.cmdrc/cmd_startup.bat

If at any time you would like to revert the changes made to the shell's script, you can do so by running Python Envs: Revert Shell Startup Script Changes via the Command Palette.

###CMD

  1. Add or update HKCU\\Software\\Microsoft\\Command Processor AutoRun string value to use a command script.
  2. A command script is added to %USERPROFILE%\.cmdrc\cmd_startup.bat
  3. A script named vscode-python.bat is added to %USERPROFILE%\.cmdrc and called from cmd_startup.bat

contents of cmd_startup.bat

:: >>> vscode python
if "%TERM_PROGRAM%"=="vscode" (
    if not defined VSCODE_PYTHON_AUTOACTIVATE_GUARD (
        set "VSCODE_PYTHON_AUTOACTIVATE_GUARD=1"
        if exist "%USERPROFILE%\.cmdrc\vscode-python.bat" call "%USERPROFILE%\.cmdrc\vscode-python.bat"
    )
)
:: <<< vscode python

contents of vscode-python.bat

:: >>> vscode python
:: version: 0.1.0
if defined VSCODE_CMD_ACTIVATE (
    call %VSCODE_CMD_ACTIVATE%
)
:: <<< vscode python

###Powershell/pwsh

  1. Runs powershell -Command $profile to get the profile location
  2. If it does not exist creates it.
  3. Adds following code to the shell profile script:
#region vscode python
if ($null -ne $env:VSCODE_PWSH_ACTIVATE) {
    Invoke-Expression $env:VSCODE_PWSH_ACTIVATE
}
#endregion vscode python

###sh/bash/gitbash

  1. Adds or creates ~/.bashrc
  2. Updates it with following code:
# >>> vscode python
# version: 0.1.0
if [ -n "$VSCODE_BASH_ACTIVATE" ] && [ "$TERM_PROGRAM" = "vscode" ]; then
    eval "$VSCODE_BASH_ACTIVATE" || true
fi
# <<< vscode python

###zsh

  1. Adds or creates ~/.zshrc (or $ZDOTDIR/.zshrc if ZDOTDIR is set)
  2. Updates it with following code:
# >>> vscode python
# version: 0.1.0
if [ -n "$VSCODE_BASH_ACTIVATE" ] && [ "$TERM_PROGRAM" = "vscode" ]; then
    eval "$VSCODE_BASH_ACTIVATE" || true
fi
# <<< vscode python

###fish

  1. Adds or creates ~/.config/fish/config.fish
  2. Updates it with following code:
# >>> vscode python
# version: 0.1.0
if test "$TERM_PROGRAM" = "vscode"; and set -q  VSCODE_FISH_ACTIVATE
    eval $VSCODE_FISH_ACTIVATE
end
# <<< vscode python

##Extension Dependency

This section provides an overview of how the Python extension interacts with the Python Environments extension and other tool-specific extensions. The Python Environments extension allows users to create, manage, and remove Python environments and packages. It also provides an API that other extensions can use to support environment management or consume it for running Python tools or projects.

Tools that may rely on these APIs in their own extensions include:

  • Debuggers (e.g., debugpy)
  • Linters (e.g., Pylint, Flake8, Mypy)
  • Formatters (e.g., Black, autopep8)
  • Language Server extensions (e.g., Pylance, Jedi)
  • Environment and Package Manager extensions (e.g., Pixi, Conda, Hatch)

###API Dependency

The relationship between these extensions can be represented as follows:

Users who do not need to execute code or work in Virtual Workspaces can use the Python extension to access language features like hover, completion, and go-to definition. However, executing code (e.g., running a debugger, linter, or formatter), creating/modifying environments, or managing packages requires the Python Environments extension to enable these functionalities.

###Trust Relationship Between Python and Python Environments Extensions

VS Code supports trust management, allowing extensions to function in either trusted or untrusted scenarios. Code execution and tools that can modify the user’s environment are typically unavailable in untrusted scenarios.

The relationship is illustrated below:

In trusted mode, the Python Environments extension supports tasks like managing environments, installing/removing packages, and running tools. In untrusted mode, functionality is limited to language features, ensuring a secure and restricted environment.

##Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

##Questions, issues, feature requests, and contributions

  • If you have a question about how to accomplish something with the extension, please ask on our Discussions page.
  • If you come across a problem with the extension, please file an issue.
  • Contributions are always welcome! Please see our contributing guide for more details.
  • Any and all feedback is appreciated and welcome!
    • If someone has already filed an issue that encompasses your feedback, please leave a 👍/👎 reaction on the issue.
    • Otherwise please start a new discussion.
  • If you're interested in the development of the extension, you can read about our development process.

##Data and telemetry

The Microsoft Python Extension for Visual Studio Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. This extension respects the telemetry.enableTelemetry setting which you can learn more about at https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting.

##Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

// Install

Open this extension directly in your IDE — no CLI, no extra tools.

Extension ID
ms-python.vscode-python-envs

If your IDE doesn't open automatically, copy the ID above and paste it into the Extensions view (⌘P ext install <id>).

// Source signals

Publisher
Verified ✓
Rating
3.0 (3)
Downloads
28.3M
Published
2026-05-07
Source
repo
Homepage
link

Live from open-vsx.org. Refreshed hourly.

// Are you the author?

This listing is mirrored from Open VSX. Claim it to ship a native OXP build, customise the page, and respond to reviews.

Claim this listing

// Package Info

Version
1.28.0
Owner
@vsx-ms-python
Downloads
26.7M
Stars
0