admin管理员组

文章数量:1180551

I'm using NixOS on WSL2 and Visual Studio Code on Windows with the WSL extension. I've created a virtual environment in NixOS, and I want to use the python command of the virtual environment as the Python interpreter in VS Code. However, I'm encountering issues selecting the correct interpreter.

My setup:

NixOS installed on WSL2

Visual Studio Code on Windows with the WSL extension (to access all file in WSL)

Python virtual environment created in NixOS (see flake at the end of the question)

When I run which python inside my virtual environment in NixOS, I get:

/nix/store/24w9ckmkq0asaif83c13z53yraq584lm-python3-3.14.0a4/bin/python

I've tried to select this path as my interpreter in VS Code by adapting it to the Windows WSL path format:

\wsl.localhost\NixOS\nix\store\24w9ckmkq0asaif83c13z53yraq584lm-python3-3.14.0a4\bin\python

However, VS Code only allows me to choose executable (.exe) files. This makes sense, as the Linux executable can't be run directly from Windows. Is it possible to select this NixOS WSL Python interpreter for use in VS Code on Windows? If so, how can I do it? I understand that a Linux executable can't be run directly from Windows, but I'm hoping there's a way to configure VS Code to use the WSL Python interpreter seamlessly. Any guidance on how to properly set this up would be greatly appreciated.

My flake file bring nothing to understand the problem. It is to make the problem reproductible:

{
  description = "Python and Manim development environment";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }@inputs:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
      in {
        devShells.default = pkgs.mkShell {
          buildInputs = with pkgs; [
            python314
            manim
          ];
          
          shellHook = ''
            echo "Development environment for Python and Manim"
            echo "Run 'python' to start Python interpreter"
            echo "Run 'manim' to start Manim"
          '';
        };
      }
    );
}

本文标签: