Search code examples
pythonraspberry-pidebiancythonraspbian

Can't install C-based modules like lxml and Cython on Python 3.6 on Raspberry Pi


I built Python 3.6 from source and am trying to install lxml. Trying to install it from pip gives the following error:

    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -Isrc -Isrc/lxml/includes -I/usr/local/include/python3.6m -c src/lxml/etree.c -o build/temp.linux-armv6l-3.6/src/lxml/etree.o -w
    src/lxml/etree.c:91:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    Compile failed: command 'gcc' failed with exit status 1
    cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitln68cjsn.c -o tmp/xmlXPathInitln68cjsn.o
    cc tmp/xmlXPathInitln68cjsn.o -L/usr/lib -lxml2 -o a.out
    error: command 'gcc' failed with exit status 1

The same error is raised if I try to install Cython to compile lxml from source. I installed libxml2-dev and libxslt1-dev, but python3.6-dev, which is apparently also required, is not found in Raspbian repository. I added the following line to /etc/apt/sources.list:

deb http://ftp.de.debian.org/debian sid main 

But when trying to install it afterwards, I receive the following error:

The following packages have unmet dependencies:
 libdbus-1-3 : Breaks: dbus (< 1.9.16-1~) but 1.6.8-1+deb7u1 is to be installed
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.

In fact, this error is raised on any package that is found in Debian repository that is not in Raspbian one. What can I do about this?


Solution

  • Since you installed Python from source, you should have the header files already. Should also use header files for the version that you built as opposed to the version in the package manager.

    Either

    • Add the source code directory to includes used by GCC (gcc -I<dir>) or
    • Install the from source package in a system directory that is automatically included like /usr/include or /usr/local/include

    The second option is probably easiest and should be possible from the standard configure/make scripts.