Python: Difference between revisions

imported>Enolan
add a bit about buildFHSUserEnv
imported>Milahu
+ Development shell
Line 22: Line 22:


We defined a function <code>my-python-packages</code> which takes as input a set <code>python-packages</code> and returns a list of attributes thereof.
We defined a function <code>my-python-packages</code> which takes as input a set <code>python-packages</code> and returns a list of attributes thereof.
== Development shell ==
=== withPackages env ===
If you need only python:
<syntaxhighlight lang="nix">
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
let
  python-with-my-packages = pkgs.python3.withPackages (p: with p; [
    pandas
    requests
    # other python packages you want
  ]);
in
python-with-my-packages.env # replacement for pkgs.mkShell
</syntaxhighlight>
=== mkShell ===
If you need python and other dependencies:
<syntaxhighlight lang="nix">
# shell.nix
{ pkgs ? import <nixpkgs> {} }:
let
  my-python = pkgs.python3;
  python-with-my-packages = my-python.withPackages (p: with p; [
    pandas
    requests
    # other python packages you want
  ]);
in
pkgs.mkShell {
  buildInputs = [
    python-with-my-packages
    # other dependencies
  ];
  shellHook = ''
    PYTHONPATH=${python-with-my-packages}/lib/python${my-python.pythonVersion}/site-packages
    # maybe set more env-vars
  '';
}
</syntaxhighlight>


== Using alternative packages ==
== Using alternative packages ==