Building a python package

I want to build the python command line interface to globusconnectpersonal. The recommended way to do it is to use pip, so I tried that:

source ~/.venv/bin/activate
pip install -r ./requirements.txt

That fails:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DUSE__THREAD -I/usr/include/ffi -I/usr/include/libffi -I/home/rmason/.venv/include -I/nix/store/yl3n75qzrfwdyv33n1vfhvk5bnv0mjpx-python3-3.10.0a5/include/python3.10 -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.10/c/_cffi_backend.o
c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
15 | #include <ffi.h>
| ^~~~~~~
compilation terminated.
error: command ‘/home/rmason/.nix-profile/bin/gcc’ failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/rmason/.venv/bin/python -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-xad9gl76/cffi_87b7fb575aff4d0381d62bc292a1cf7e/setup.py’“'”‘; file=’“'”‘/tmp/pip-install-xad9gl76/cffi_87b7fb575aff4d0381d62bc292a1cf7e/setup.py’“'”‘;f=getattr(tokenize, ‘"’“‘open’”’“‘, open)(file);code=f.read().replace(’”‘"’\r\n’“'”‘, ‘"’"’\n’“'”‘);f.close();exec(compile(code, file, ‘"’“‘exec’”’"‘))’ install --record /tmp/pip-record-uos5eris/install-record.txt --single-version-externally-managed --compile --install-headers /home/rmason/.venv/include/site/python3.10/cffi Check the logs for full command output.

Should I be using nix-shell? I have looked at https://nixos.wiki/wiki/Python ’ Emulating virtualenv with nix-shell’ but the example is incomplete. What am I supposed to put in that example’s shell.nix where it has ‘= …build expression for this python library…;’?

I’m a newbie and I need a bit of hand-holding.

Thanks,
Roger

We all need a bit of handholding, especially when it comes to some of the language ecosystems.

Generally when your goal is “install everything from this package’s language-specific-dependency-spec-file”, you’ll want to use a third-party project to generate Nix expressions for them. (You could write them by hand, but it’s not newbie friendly, and you’ll have two copies of the dependency spec to keep in sync.)

There have been multiple swings at getting this right for the Python ecosystem, but in my experience the best (and most newbie-friendly) is GitHub - DavHau/mach-nix: Create highly reproducible python environments. I’d follow the introduction there to see if it can generate a working expression.

Hello,

abathur via NixOS Discourse writes:

There have been multiple swings at getting this right for the Python
ecosystem, but in my experience the best (and most newbie-friendly) is
GitHub - DavHau/mach-nix: Create highly reproducible python environments. I’d follow the introduction there
to see if it can generate a working expression.

Yes, that worked.

Thank you,
Roger