Change:
for prg in *; do if [ -f "$prg" ]; then rm -f "$out/bin/$prg" <del> makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" </del> <ins> makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set PYTHONHOME "$out" --set PYTHONNOUSERSITE "true" </ins> fi done fi

Discussion:
By default Python adds the user site-directory to . We should prevent it from doing this in our applications to prevent (bugs due to) impurities.
I didn't find this bug because I looked in the wrong place, so I went and created , which I've now closed. I'm pasting the text from that issue here because it fleshes out this issue somewhat. Setup I'm using nix as a package manager on top of Ubuntu. This problem may also exist on NixOS, I don't know. To trigger the bug we need a system python install with pip and the same python version in nix. I'll use 3.5 in this example, so make sure Python 3.5 is installed with whatever package manager the OS uses, for example: sudo apt-get install python3.5 We also need to make sure that the directory containing user-installed packages exist. I'm using lxml to illustrate a particular problem with this bug, but any package can be used. I'm also using to make certain I'm using the right pip. python3.5 -m pip install --user --upgrade lxml It may be possible to use a nix-shell with pip to achieve the same effect, but I haven't tested this. Reproduce bug Again, any python package may be used, but I'm using BeautifulSoup4 as an example. It's important that the python version matches the one used in the setup. nix-shell --pure -p pkgs.python35Packages.beautifulsoup4 --run  "python -c 'import sys; print(, sep="n")'" | grep ".local" Expected behaviour No output. Observed behaviour Output like this: Consequences All the packages the user has ever installed with (and their dependencies) are importable in the pure nix environment, which is not expected behavior. Fortunately, the nix-provided python packages override the user-installed packages, so the explicit dependencies of any nix package always have the correct versions. Unfortunately, there are several packages whose behaviour depends on what packages are available for import. For example, BeautifulSoup has a prioritized list of html parsers and . So the expected behaviour -- that a script will run the same way no matter the environment if run in a pure nix shell -- is wrong.

Instead, the script runs differently depending on what modules the user has installed using . This is not a special case. A quick search through the installed python modules on my PC show that import statements inside clauses are very common in python code, so the real-life effect of having lots of unexpected packages available for import is almost certainly considerable. Temporary workaround A workaround until this is fixed is to use the switch to python: $ nix-shell --pure -p pkgs.python35Packages.beautifulsoup4 --run  $ Mitigation describes the mechanism used to insert the path to the user-installed packages into , so a solution would involve one of the options presented in that document, for example setting to in , or setting the environment variable.
yes, we need to update our wrappers and to set . This will have to go in before 17.09.