I am running Nix 2.4. I know how to use, e.g., nix run and nix shell for packages in the nixpkgs flake (e.g., nix run nixpkgs#gimp, et al.). But I cannot figure out how to do this for Python.
Simple example that just tripped me up–I want to use the Python requests package in an ad hoc environment. I tried nix shell nixpkgs#python38Packages.requests, which looks like it worked, but then:
$ python
Python 3.8.11 (default, Jun 28 2021, 10:57:31)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
>>>
What is the right way to do this?
EDIT: I forgot to mention–it seems the old-school way to do this is nix-shell -p python38Packages.requests, which works (I am able to import requests in a Python shell). My question can be stated another way as: what is the new-school way to do this?
nix shell doesn’t execute shellHooks, which is how python38Packages.requests exports a PYTHONPATH with itself and it’s dependencies.
You could use nix develop with a derivation which has requests as a dependency. But AFAIK, there is not an exact replacement for all that nix-shell -p provided.