Disclaimer:
- I don’t know if it is proper or not. But it should work.
- I’m not an expert, improvement is welcome! I hope if it’s good enough, it will be on the wiki.
- This guide uses Spyder 6.1.2 with Qt6 webengine support (currently in unstable).
- Don’t use older Spyder with Qt5 webengine version. Since it contains lot CVE’s and not in nix cache so you need to built it yourself.
- I use NixOS with home-manager, flake and direnv. But you should able to adapt this to your configuration.
Install Spyder:
We must put Spyder and its dependecies inside single python closure so Spyder can’t detect the dependencies. If you set the Spyder python interpreter with internal path, you can use Spyder everywhere as long the python package in your code is also installed in that python clouse.
packages = with pkgs-unstable; [
(python3.withPackages (python-pkgs: with python-pkgs;[
spyder
spyder-kernels
pandas # optional
]))
];
You can install bare Spyder like below, but you must install spyder-kernels package in your python environment and set that Spyder’s python interpreter path to that environment. In this mode, even if your environment has pandas, it won’t be detected by Spyder GUI so no dataframe visualization. The code will still work.
packages = with pkgs-unstable; [
spyder
];
For example, I use this flake with direnv for my python environment. Would be better if you learn direnv first. The important part is the $LD_LIBRARY_PATH export. Spyder must be called from the direnv console with that $LD_LIBRARY_PATH environment variable. To install the direnv environment we call $ nix develop .#setupShell which also install spyder-kernels in the python virtual environment.
description = "test";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
buildInputs = [
(pkgs.python3.withPackages (python-pkgs: [
python-pkgs.pip
python-pkgs.virtualenv
]))
];
in {
devShells.default = pkgs.mkShell {
inherit buildInputs;
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath buildInputs}:$LD_LIBRARY_PATH"
source .venv/bin/activate
'';
};
devShells.setupShell = pkgs.mkShell {
inherit buildInputs;
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib/
rm -rf .venv
virtualenv --no-setuptools .venv
source .venv/bin/activate
pip install spyder-kernels==3.1
'';
};
});
}