`pythonPackages.foobar` vs `python3.pkgs.foobar` vs using `withPackages`?

Are there meaningful differences between these three ways of using python packages? Thus far I’ve been using them interchangeably.

EDIT: And not to be forgotten is also python3Packages.foobar!

python3Packages is aliased to python3.pkgs, so those are equivalent.

python3.withPackages will actually do a buildenv and create a python interpreter which “has all the dependencies pre-installed”. You can think of it like creating the nix version of a venv.

2 Likes

Thanks, that makes sense! And I’m assuming pythonPackages.foobar is python2 only?

if you’re referring to the interpreter, yes

$ nix eval -f . pythonPackages.python.version
"2.7.18"
[22:52:48] jon@jon-desktop /home/jon/projects/nixpkgs (master)
$ nix eval -f . python3Packages.python.version
"3.8.7"

it’s pointing to python2 for historical reasons

So if I want to be able to use ipython in the normal user session (without nix-shell), and I want to have all stated libraries available, I guess I need to use pythonX.withPackages in the system or user configuration. Is that so?

Yes. If you want to install it as part of the “system”, please refer to nixpkgs/python.section.md at d1f97a5eb5115289071d8449f26e7b92ce6b6709 · NixOS/nixpkgs · GitHub