How install python packages globally with home manager?

I wish to configure my nix machines so that whenever I launch python all installed packages are available with out needing a custom environment. I am using home manager to manage my user’s packages. I have tried home.packages = with pkgs; [... python311 python311Packages.numpy ...]; however when I launch a python prompt and try and import numpy python says the module cannot be found.

Most answers I can find use .withPackages however I cannot find how to use this with home manager. If this questions has been answered before I do apologise but I could not find the answer.

I am fairly new to nix.

Something like this:

{pkgs, ...}: {
  home.packages = [
    (pkgs.python311.withPackages (ppkgs: [
      ppkgs.numpy
    ]))
  ];
}
2 Likes