I had an issue when I installed Yapf
this way:
environment.systemPackages = with pkgs; [
(python311.withPackages(ps: with ps; [
toml
python-lsp-server
pyls-isort
flake8
]))
pkgs.yapf
];
This gave me the error:
$ yapf autoapp.py yapf: toml package is needed for using pyproject.toml as a configuration file
And I solved when I did:
environment.systemPackages = with pkgs; [
(python311.withPackages(ps: with ps; [
toml
python-lsp-server
pyls-isort
flake8
yapf
]))
];
Why was the first configuration giving me an installed version of yapf that couldn't import toml?
These are the same package - you can see this by checking the source links from the package search page. Adding it to withPackages
links the Python package with the interpreter, making it possible to run things like python -m yapf …
or import yapf
within the Python REPL. If you simply list pkgs.yapf
at the top level, the package isn't linked to the Pyython interpreter, and so only things like man
pages and executables are available in the resulting environment.