VS Code: Python Environments Extension generally available

The new extension for Visual Studio Code aims to end the previous fragmentation and ensure a uniform workflow with Python environments.

listen Print view
A hand points to the lettering Python

(Image: Funtap / Shutterstock.com)

3 min. read

As Microsoft announced, the Python Environments Extension for Visual Studio Code is generally available after a one-year preview phase. It is intended to make the workflow for managing Python environments more consistent and to counteract fragmentation across tools like venv, conda, poetry, and pipenv.

Within the next few weeks, all Python environment workflows will automatically switch to the new extension. Those who want to use it now can set the python.useEnvironmentsExtension setting. The extension works in conjunction with the Python extension and should not require any further setup.

Videos by heise

When opening a Python file, the Python Environments Extension automatically recognizes environments from all common technologies in the ecosystem: venv, conda, pyenv, poetry, pipenv, and system Python installations. Behind this is the Python Environment Tool (PET), a Rust-based scanner for finding environments. It checks the PATH, known installation locations, and configurable search paths.

In the Python Extension, PET has already been used, but now also offers a dedicated user interface for creating, deleting, switching, and managing environments.

A look at the new Python Environments Extension

(Image: Microsoft)

If the uv package manager is installed, the Python Environments Extension automatically uses it to create venv environments and install packages. This is expected to be significantly faster than with standard tools, especially in large projects, and is enabled by default (python-envs.alwaysUseUv).

To create a new environment, developers click on Quick Create (the + button in the Environment Manager view). The extension then creates a new environment with the default manager, the latest Python version, and Workspace Dependencies found in the requirements.txt or pyproject.toml files. Custom creation is possible with Custom Create, accessible via "Python: Create Environment" in the command palette. Then the aforementioned points can be selected manually.

Among other features, environments can be assigned to specific folders or files. This is intended to resolve common problems, including in monorepos and when dealing with multi-version testing. When a project is assigned an environment, the extension saves the environment manager type, but not hardcoded interpreter paths. This makes the .vscode/settings.json file portable across devices, operating systems, and team members.

Furthermore, the Python extension now uses the Python Environments API to enable multi-project testing. Hints for this are provided in the guide on GitHub.

Further details can be found in the blog post about the release of the Python Environments Extension. It can be found in the Visual Studio Marketplace, although it is still marked as a preview there.

(mai)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.