Python: Difference between revisions

m Remove mention of pip2nix. This tool just barely works and shouldn't be mentioned in this context.
Use python.override correctly instead of incorrect inline hack.
Line 68: Line 68:
let
let
   pkgs = import <nixpkgs> {};
   pkgs = import <nixpkgs> {};
  python = pkgs.python3.override {
    self = python;
    packageOverrides = pyself: pyfinal: {
      toolz = pyfinal.callPackage ./toolz.nix { };
    };
  };
in pkgs.mkShell {
in pkgs.mkShell {
   packages = [
   packages = [
     (pkgs.python3.withPackages (python-pkgs: [
     (python.withPackages (python-pkgs: [
       # select Python packages here
       # select Python packages here
       python-pkgs.pandas
       python-pkgs.pandas
       python-pkgs.requests
       python-pkgs.requests
       (pkgs.callPackage ./toolz.nix)
       python-pkgs.toolz
     ]))
     ]))
   ];
   ];
}
}
</syntaxhighlight>Note that the parenthesis (line 10) are required.
</syntaxhighlight>Next time you enter the shell specified by this file, Nix will build and include the Python package you have written.
 
Next time you enter the shell specified by this file, Nix will build and include the Python package you have written.
==== Using nix-shell alongside pip  ====
==== Using nix-shell alongside pip  ====
When working on a collaborative python project you may want to be able to <code>pip install -r requirements.txt</code> if the project isn't packaged for nix specifically.
When working on a collaborative python project you may want to be able to <code>pip install -r requirements.txt</code> if the project isn't packaged for nix specifically.