Vscode python libraries

hi all, and if I want to install python libraries declaratively, and not via pip, how can I do it? all I could do so far is:

                vscode = {
                  enable = true;
                  enableUpdateCheck = false;
                  enableExtensionUpdateCheck = false;
                  extensions = with pkgs.vscode-extensions; [
                    bbenoist.nix
                    ms-vscode.cpptools
                    ms-vscode.cpptools-extension-pack
                    ms-vscode.cmake-tools
                    github.copilot
                    github.copilot-chat
                    ms-python.python
                    ms-python.debugpy
                  ];
                  userSettings = {
                    python.formatting.blackPath = "${pkgs.black}/bin/black";
                    python.defaultInterpreterPath = "${pkgs.python3Full}/bin/python";
                    terminal.integrated.shell.linux = "${pkgs.zsh}/bin/zsh";
                  };
                };

set the default interpreter to the one I need and install libraries like this:

                    (pkgs.python3Full.withPackages (python-pkgs:
                      with python-pkgs; [
                        # select Python packages here
                        pandas
                        numpy
                        lxml
                        scapy
                        dbus-python
                        requests
                      ]))

but this seems to be limited to the nixpkgs repository

Ideally you would add these packages to your project (either via your devShell or your Python package manager) and configure the VSCode project settings accordingly.

If you use direnv and an extension for it it will work much better.

1 Like

It’s not exactly what you asked, but did you know about https://devpod.sh/? It’s a nice tool for creating and sharing repeatable development environments.

Something like devenv.sh probably matches better for someone on this forum.

I found dream2nix and it seems to be the solution to my problem

1 Like

Thanks, I’ll take a look at it.

In that case uv2nix would be an option as well.

I like devenv.sh a lot, thanks for sharing it!

Glad that you like it.
As an FYI I only use the flakes implementation to start the services.
I don’t really use their CLI tools as I don’t want to depend on too many tools.

Services flake might serve the same purpose.

1 Like

Dully noted. Thanks for the extra info.