Skip to content

How to use Hatch environments from Visual Studio Code

Visual Studio Code announced support for Hatch environment discovery in vscode-python's 2024.4 release.

For it to work, you should install Hatch globally. If you used the GUI installers on Windows or macOS, or your system package manager on e.g. Arch Linux or Fedora, this should be taken care of.

Setting up PATH

If you installed Hatch with pipx rather than system-wide, you might need to add $HOME/.local/bin to your PATH environment variable for your graphical session, not just your terminal. Check like this:

$ pgrep bin/code  # or some other graphical application
$ cat /proc/1234/environ | tr '\0' '\n' | grep -E '^PATH='

If the directory is not in there, you need to add it in your session startup script, in a way that depends on your desktop environment:

Project setup

  1. Make Hatch install the project and its dependencies to an environment using the env create command.

  2. Select an interpreter using the Python: Select Interpreter command:

    Select interpreter

  3. You should now be able to use the environment. For example, if you have the python.terminal.activateEnvironment setting set to true and you open a new terminal, the environment should be activated. Alternatively, you could press the "play" button to run a file in the environment:

    Run file