Using Qtile changes Python environment

Hello everyone,

I have a problem similar to the one discussed on this reddit forum, which deals with some clash of Python environments when installing Qtile on NixOS. To elaborate, I have this on my configuration.nix:

services.xserver.windowManager = {
  qtile = {
    enable = true;
  };
};
...
environment.systemPackages = with pkgs; [
...
 (let
  my-python-packages = python-packages: with python-packages; [
    matplotlib
    numpy
    pandas
    scikit-learn
  ];
  python-with-my-packages = python3.withPackages my-python-packages;
  in
    python-with-my-packages)
...
];

If I disable Qtile I am able to work with my globally defined Python environment:

$ python -c "import numpy"
$ python -c "import sys; print(sys.prefix)"
/nix/store/kc9bsiwsbadhs165ryr4b6xbsb0wccmc-python3-3.9.6-env

However, when I enable Qtile the Python environment changes, and the packages I added globally are not available anymore:

$ python -c "import numpy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
$ python -c "import sys; print(sys.prefix)"
/nix/store/z43s37a755b2i8nd6mibjzjjjjdl7f3n-qtile-0.18.1

How could I use Qtile and at the same time keep my global environment?

eh, probably this is due to how qtile is packaged, as it uses .withPackages as well. This is the relevant lines from its package definition:

(python3.withPackages (_: [ unwrapped ])).overrideAttrs (_: {
  # otherwise will be exported as "env", this restores `nix search` behavior
  name = "${unwrapped.pname}-${unwrapped.version}";
  # export underlying qtile package
  passthru = { inherit unwrapped; };

  # restore original qtile attrs
  inherit (unwrapped) pname version meta;
})

… this final package is then added to systemPackages when you enable qtile. So both packages (yours and qtile’s) add a python executable to the PATH and it seems that qtile’s is the one that comes first in the PATH and gets invoked.

Now, I don’t know why qtile packager did this because I don’t use it, the best thing to do is to open an issue or a pull request on nixpkgs

1 Like

Thank you very much for your reply. The issue has been solved by #167381.