Hi. I’m looking for canonical solution to following problem (like, I know the solution, but maybe there’s something better)
with import <nixpkgs> {};
mkShell rec {
reqs = writeText "requirements.txt" ''
lxml
'';
shellHook = ''
alias pip="PIP_PREFIX='$(pwd)/build/pip_packages' \pip"
export PYTHONPATH="$(pwd)/build/pip_packages/lib/python2.7/site-packages:$PYTHONPATH"
unset SOURCE_DATE_EPOCH
pip install -r ${reqs}
'';
}
This code tries to install lxml
Python library via pip
. It fails with
cc -I/usr/include/libxml2 -c /run/user/1000/xmlXPathInitcQjVdW.c -o run/user/1000/xmlXPathInitcQjVdW.o
/run/user/1000/xmlXPathInitcQjVdW.c:1:10: fatal error: libxml/xpath.h: No such file or directory
#include "libxml/xpath.h"
^~~~~~~~~~~~~~~~
compilation terminated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/nix/store/5xl4sc0fv2gcj0cbnvxja14yl89nk5c6-python-2.7.14/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/run/user/1000/pip-build-iOkjh0/lxml/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /run/user/1000/pip-775R70-record/install-record.txt --single-version-externally-managed --prefix /home/danbst/dev/build/pip_packages --compile" failed with error code 1 in /run/user/1000/pip-build-iOkjh0/lxml/
Which is understandable - there are no includes for libxml2. But when I add
buildInputs = [ libxml2 ];
It still doesn’t work. Why?
What works is the following:
buildInputs = [
libxml2
libxslt
];
C_INCLUDE_PATH =
"${libxml2.dev}/include/libxml2:" +
lib.makeSearchPathOutput "dev" "include" buildInputs;
But I don’t understand why should I specify C_INCLUDE_PATH
- it’s mkDerivation
job AFAIK.