$ nix-shell
[nix-shell:~/pip-test]$ python -m pip install sampleproject
Collecting sampleproject
Using cached sampleproject-2.0.0-py3-none-any.whl (4.2 kB)
Collecting peppercorn
Using cached peppercorn-0.6-py3-none-any.whl (4.8 kB)
Installing collected packages: peppercorn, sampleproject
ERROR: Could not install packages due to an OSError: [Errno 30] Read-only file system: '/nix/store/5bh6rpya1ar6l49vrhx1rg58dsa42906-python3-3.9.6/lib/python3.9/site-packages/peppercorn'
WARNING: You are using pip version 21.1.3; however, version 21.3.1 is available.
You should consider upgrading via the '/nix/store/5bh6rpya1ar6l49vrhx1rg58dsa42906-python3-3.9.6/bin/python -m pip install --upgrade pip' command.
python packages are a bit odd in that you have to install them as part of an interpreter environment, not as an interpreter and separate packages for it to use. in this case you’d use
with (import <nixpkgs> {});
mkShell {
buildInputs = [
(python39.withPackages (p: with p; [ pip setuptools ]))
];
}
this is explained in more detail on the wiki page about python, and also holds for other interpreted languages like perl and ruby.
seems i was a little hasty and imprecise with the reply, sorry about that.
nix python is built around the idea to not use pip. everything should be a derivation that’s included in a python environment. there are ways around that, the most common these days seems to be to use poetry and poetry2nix. while it might seem convoluted there is a reason to that, using pip introduces many reproducibility issues into the packaging process and by default (as you’ve experienced) wants to write to global locations in the system.
that’s not to say you’re doing it wrong. if it works, it works! but the “clean”, nixy way would be to not use pip/venv.
@pennae, your reply pointed me to the solution, thank you!
Yeah, the only reason that I’m using pip is that I’m trying to diagnose a problem with a NixOS package. I’m hoping that if I can build the software the way the developer intended (using pip), I can rule out an upstream issue. Then I can figure out what the (rather complex) default.nix in NixOS/nixpkgs is doing differently, and maybe fix it.