Could you please post the shell.nix
you’ve been using so we can try to reproduce your problem?
Unfortunately, I deleted it. Oh well, it doesn’t matter, if these new ones are working.
My current (apparently working) shell.nix is
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "example";
buildInputs = with pkgs; [
pkgconfig
openssl
postgresql
python36Full
python36Packages.pip
];
}
Adapting it to the style you suggested (while still using venv) appears to have no visible effect to me.
Why do you need venv? The nix-shell above should contain a Python interpreter with all the packages you need (similar to a venv).
I need to work within the existing tooling of the projects that I work on. These assume build tools like poetry
(which calls out to pip
), and pip
directly. So I can go and add python36Packages.pip
to the build inputs, but then see ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/nix/store/.../site-packages/....
, which makes sense given what I know about how nix works.
Then from the above linked article, I can set PIP_PREFIX
and PYTHONPATH
in order to have pip/python install to and read from a writeable location to fix that.
While this initially seems to work, if I try to include any python packages (like ptpython) in the shell.nix, trying to install the requirements.txt
eventually fails with
Found existing installation: six 1.12.0
Uninstalling six-1.12.0:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 'RECORD'
because presumably ptpython or some upstream dep of it requires a different version of six
, pip wants to swap the version, but that version is in a read-only location.
Removing that, proceeds past dependency installation, but fails at editably installing the project’s package with
Checking .pth file support in .../_build/pip_packages/lib/python3.7/site-packages
/nix/store/jn8dic1klsd1d550wb682ssnq9wsffg5-python3-3.7.5/bin/python3.7 -E -c pass
TEST FAILED: .../_build/pip_packages/lib/python3.7/site-packages does NOT support .pth files
error: bad install directory or PYTHONPATH
Which I have no idea how to solve.
I wish I had my previous shell.nix, because with that, I had had something which could install everything (seemingly correctly, despite the openssl errors at runtime) but there was some issue with executing bash scripts which called out to python.
So far for me, it seems as though unless I’m willing to go through a lot of preparation before working on any project, or go all-in on using nix as the tooling (which i cant), these sorts of issues have cropped up in various places.
Unless there’s some silver bullet that’s guaranteed to solve all these issues, I think, for now, I’m happy just using it to obtain a working python interpreter specific to the project (which allows me to drop pyenv/brew), and then manage everything after that point the same way is typical for python development.