PyCharm using nix-shell

Is there a way to get PyCharm to use nix-shell and not a venv?

All answers I found were more than 5 years old, and maybe there are better solutions now possible.

{
  system ? builtins.currentSystem,
  pkgs ? import <nixpkgs> { inherit system; }
}:
let
  pythonEnv = pkgs.python3.withPackages (ps: [
    ps.numpy
    ps.scipy
    ps.matplotlib
    ps.pandas
    ps.jupyter
  ])
in
pkgs.mkShell {
  packages = [ pythonEnv ];
  shellHook = ''
    ln -snf ${pythonEnv} .python-env
  '';
}

Then use .python-env in PyCharm

1 Like

Thank you so much! I spent too many hours with horrible workarounds and should have asked earlier.

In the solution above, a “;” is missing so I add the working code below if someone else has the same problem as I had.

# shell.nix
{
  system ? builtins.currentSystem,
  pkgs ? import <nixpkgs> { inherit system; }
}:
let
    pythonEnv = pkgs.python3.withPackages (ps: [
    ps.numpy
    ps.scipy
    ps.matplotlib
    ps.pandas
    ps.jupyter
  ]);

in pkgs.mkShell {
    packages = [ pythonEnv ];
  shellHook = ''
    ln -snf ${pythonEnv} .python-env
  '';
}
2 Likes