So how do i do ‘pip3 install requests’ for example?

$ nix-shell -p python3Packages.requests

Nix generally only manifests temporary environments, rather than mutating global state. For a more Pythonic environment, try the direnv integration, which will let you both `use nix` and also `use python3` together, as long as it's in that order.

This exact thing is what trips me up about using Nix and I haven't been able to figure out how to get around it. Sometimes you want a global Python library. Here's one example from my own use case: I want to use a Weechat Python script that depends on a Python library called "pync". With e.g. MacPorts I can just run

    sudo port install py-pync
and now the Weechat Python script will be able to "import pync". But this doesn't work with Nix since every package is completely isolated from each other.

I spent quite a bit of time trying to figure this out and was unsuccessful. I'd love to know what Nix's answer to use cases like this is.

What you're looking for is `(python3Packages.withPackages (ps: with ps; [ pync ... ]))`

This will create a python which has pync and other packages in the sitePackages already.

That works for a temporary development environment in e.g. shell.nix. But what about the global environment?

    nix-env -i -f '' -E 'f: (f {}).python3.withPackages (ps: with ps; [pyyaml requests])'
But you don't want to install globally. One of major strengths (for me at least) is that when combined with nix-shell you have something like virtualenv, but for all packages, not just the ones from python.

This means that someone else who checks out your project can get the same environment you had for the development.

If this is combined with direnv, then you don't even need to invoke nix-shell you just enter the project directory and everything is there.

If you use something like poetry2nix[1] it will automatically have the dependencies your project has.

[1] https://github.com/nix-community/poetry2nix