nix-community / pip2nix

Freeze pip-installable packages into Nix expressions [maintainer=@datakurre]
175 stars 26 forks source link

Usage example #59

Closed adfaure closed 3 years ago

adfaure commented 4 years ago

Hello, following your README, I have been able to generate the python-packages.nix, however, it is not clear to me how I can use it.

Do you have an example somewhere?

My objective is to install the packaged application into a shell (for instance).

Thank you !

yanganto commented 3 years ago

The python-packages.nix is correctly generated by the pip2nix build with #60, and I run into the same problem here.
And here is the shell.nix I have tried. Please help me to correctly use pip2nix in nix shell. Thank you.

let pkgs = import <nixpkgs> { };
in
let
  python-packages = import ./python-packages.nix {
    pkgs = pkgs.python3.pkgs;
    fetchurl = pkgs.fetchurl;
    fetchgit = pkgs.fetchgit;
    fetchhg = pkgs.fetchhg;
  };
  python-with-packages = python-packages pkgs.python3;
in
pkgs.mkShell {
  nativeBuildInputs = [
    python-with-packages
  ];
}
datakurre commented 3 years ago

@yanganto I will try that out today and see what's missing.

datakurre commented 3 years ago

@yanganto These worked for me:

$ pip2nix generate fastapi
let pkgs = import <nixpkgs> { };
in                                                                         
let                                                                        
  packageOverrides = pkgs.callPackage ./python-packages.nix {};
  python = pkgs.python3.override { inherit packageOverrides; };
  pythonWithPackages = python.withPackages(ps: [ ps.fastapi ]);   
in
pkgs.mkShell {    
  buildInputs = [                       
    pythonWithPackages                       
  ];
}

Without custom packages

$ nix-shell -p "python3.withPackages(ps: [ ps.fastapi ])" --run "python -c 'import fastapi; print(fastapi.__version__)'"
0.55.1

With custom packages:

$ nix-shell --run "python -c 'import fastapi; print(fastapi.__version__)'"
0.63.0
yanganto commented 3 years ago

@datakurre Thank you. May I add this into readme or make an example file in this project and close this issue? 😄

datakurre commented 3 years ago

Please do 😍