[Python] How to load PEP-723-style venvs in vscode automatically

Discussão em 'Python' iniciado por Stack, Março 29, 2025.

  1. Stack

    Stack Membro Participativo

    When writing Python scripts, I have started using the pattern from PEP-723 with uv to create self contained scripts that uv can run directly.

    For example, here's the metadata in one of my Python scripts, which instructs uv to create a venv with duckdb and pandas to run the script:

    # /// script
    # dependencies = [
    # "duckdb>=1.2.0",
    # "pandas",
    # ]
    # ///


    The issue I'm facing is that when I edit these scripts in vscode, the venv is not automatically created and pylance complains that it can't find the packages the script is using.

    How can I automatically create such venvs in vscode so that every time I open a script like this I get pylance to use the same venv uv will create to run the script?

    Continue reading...

Compartilhe esta Página