1

I have a shell built with nix-shell foo.nix. I would now like to install a python package with the classic python setup.py install. When I attempt this I get the message [Errno 13] Permission denied: '/nix/store/kp0qz36y3cwbhwb65sw5f2vqbbnhs8dg-python3-3.7.11-env/lib/python3.7/site-packages/test-easy-install-30257.write-test'

I can do this python setup.py install --prefix=$out --root=$out which seems to succeed, however I'm unable to import the package I just installed.

How can I install this package, either by modifying foo.nix or just manually doing something within the nix shell.

On the advice of Charles Duffy I have attempted to do all this in a virtualenv and it behaves in the same way. python setup.py install in the virtualenv gives me [Errno 13] Permission denied: '/nix/store/kp0qz36y3cwbh....

If I install with python setup.py install --prefix=$VIRTUAL_ENV it appears to work but I cannot import the package. Same with the --user option. I guess I could go and just manually edit the python path to force this to work, but that's not ideal.

alessandro
  • 363
  • 1
  • 12
  • Err. You should only be running `python setup.py install --prefix=$out --root=$out` inside a Nix derivation, not an interactive nix-shell. And even then, nixpkgs has builtins that'll do the `setup.py` invocation for you. – Charles Duffy Nov 09 '21 at 22:14
  • (your deleted self-answer is very much on the right track) – Charles Duffy Nov 09 '21 at 22:15
  • It doesn't work though. I thought it did but python was doing a local import because of the directory I happened to be in when I tested it. – alessandro Nov 09 '21 at 22:36
  • I'm really not interested in learning how to use nix. I'm sure it's great, but I don't have the time or desire to learn yet another programming language right now. I just need to install this library so I can get on with my actual work. – alessandro Nov 09 '21 at 22:47
  • 1
    If you just want to do the easiest/simplest/fastest possible thing that Makes It Work without regard to whether that's the Right Thing as such, I'd suggest installing your package in a virtualenv; virtualenv is part of nixpkgs, and works the same way on NixOS as it works anywhere else. – Charles Duffy Nov 09 '21 at 23:47
  • ...whereas if you want a proper answer to this question, I'd need a [mre] showing a _specific_ Python package you want to import from a `shell.nix`; can't test an answer without enough details to create the specific problem on one's own machine, and I can't tell what dependencies some hypothetical unspecified Python package will have. – Charles Duffy Nov 09 '21 at 23:50
  • (similarly, a concrete `shell.nix` to extend/modify would be called for, if you wanted a proper, testable/tested, Right Thing answer) – Charles Duffy Nov 09 '21 at 23:52
  • Okay, thanks for your help. Yes, a virtualenv would be fine for my use case (this just needs to work once on one machine). I did end up getting this package to (attempt to) install though nix-shell, but I need sort out a bunch of dependencies if I want it working that way. – alessandro Nov 10 '21 at 00:26
  • The more I learn about nix the more I respect what it's trying to do and the way it works, but there is only so much time available... – alessandro Nov 10 '21 at 00:31

0 Answers0