nrj
May 25, 2021, 10:04pm
1
-p
works fine:
% nix-shell -p 'python38.withPackages(ps: with ps; [ numpy toolz ])' --run 'python3 -c "import numpy; print(numpy)"'
<module 'numpy' from '/nix/store/fgrhd0k14195zb9gnsrw71bybi6b00q8-python3-3.8.8-env/lib/python3.8/site-packages/numpy/__init__.py'>
Why doesn’t -E
do the same thing?
nix-shell -E 'let pkgs = (import <nixpkgs> {}); in pkgs.python3.withPackages(ps: with ps; [numpy])' --run 'python3 -c "import numpy"'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
NobbZ
May 25, 2021, 10:15pm
2
Because the latter is not equivalent. It provides an environment suitable to build the given expression. Not an environment that has what is in the result of the expression.
man nix-shell
even has some shirt section how to translate -p
to -E
using mkShell
(IIRC) and it’s buildInputs
.
FRidh
May 26, 2021, 4:51am
3
Add .env
$ nix-shell -E '(let pkgs = (import <nixpkgs> {}); in pkgs.python3.withPackages(ps: with ps; [numpy])).env' --run 'python3 -c "import numpy; print(numpy)"'
2 Likes
NobbZ
May 27, 2021, 11:04am
5
It was typed on a mobile, and that “corrected” “short” to “shirt”
1 Like
well what ever it was, it gave me a much needed LOL, and we got a bit of nix tee’s marketing for free.