Venv --system-site-packages seems not to work on NixOS

I’m trying to create a python venv so I can locally install a package via pip like e.g. solidpython2 but I want for it to inherit my meticulously crafted list of global python packages.

In a normal world I would just do python -m venv --system-site-packages venv to create such environment but this seems to have no effect on NixOS.

When I open my global python console I can import my global modules. But after I activate the venv - even though created with --system-site-packages - and use the venv python, I can’t import my global modules.

Don’t get me wrong, I’ve written my shares of flakes with buildPythonPackage galore and devShells with python3.withPackages. But if I’m going to have to go this way each time I just want to try some new python package from PyPI or have to reinstall my global list of python packages I absolutely always use into every new venv I create, I’m going loose it :sob:

Any ideas? Thanks.

As you have seen, system-site-packages is not working (I think it’s as intended?).

You don’t need to reinstall your global list, an alternative is to have a wrapper that does something like python3.withPackages (ps: globalList ps ++ [ $custom ]) and then you would pass appropriately the variable.

Of course, it does not solve the problem of testing a random package from PyPI, it has low chance of working on NixOS anyway if you are not using something like nix-ld.

In that case, you are better off using completely nix-ld IMHO and just having a proper user site from which you would inherit.

(Personally, I think it’s a feature that pip install $randompackagewithalotofmalwarethattyposquatt fails, but that’s a personal opinion.)