Unable to install lxml on Jetson Nano

Hi. I am trying to install the lxml library required for TensorFlow Object Detection API by executing: pip install lxml (inside a Python3 virtual environment). I am meeting with the following error:

Collecting lxml
  Downloading https://files.pythonhosted.org/packages/e4/19/8dfeef50623892577dc05245093e090bb2bab4c8aed5cad5b03208959563/lxml-4.4.2.tar.gz (2.6MB)
     |████████████████████████████████| 2.6MB 58kB/s 
Building wheels for collected packages: lxml
  WARNING: Building wheel for lxml failed: [Errno 13] Permission denied: '/home/pyimagesearch/.cache/pip/wheels/73'
Failed to build lxml
Installing collected packages: lxml
    Running setup.py install for lxml ... error
    ERROR: Command errored out with exit status 1:
     command: /home/pyimagesearch/.virtualenvs/py3cv4/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hdz59_f3/lxml/setup.py'"'"'; __file__='"'"'/tmp/pip-install-hdz59_f3/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 /tmp/pip-record-9rvpxls3/install-record.txt --single-version-externally-managed --compile --install-headers /home/pyimagesearch/.virtualenvs/py3cv4/include/site/python3.6/lxml
         cwd: /tmp/pip-install-hdz59_f3/lxml/
    Complete output (93 lines):
    Building lxml version 4.4.2.
    Building without Cython.
    ERROR: b'/bin/sh: 1: xslt-config: not found\n'
    ** make sure the development packages of libxml2 and libxslt are installed **
    
    Using build configuration of libxslt
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-aarch64-3.6
    creating build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/sax.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/builder.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/ElementInclude.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/doctestcompare.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/pyclasslookup.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/__init__.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/usedoctest.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/_elementpath.py -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/cssselect.py -> build/lib.linux-aarch64-3.6/lxml
    creating build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/__init__.py -> build/lib.linux-aarch64-3.6/lxml/includes
    creating build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/html5parser.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/clean.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/defs.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/_setmixin.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/builder.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/_html5builder.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/_diffcommand.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/__init__.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/formfill.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/ElementSoup.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/diff.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/usedoctest.py -> build/lib.linux-aarch64-3.6/lxml/html
    copying src/lxml/html/soupparser.py -> build/lib.linux-aarch64-3.6/lxml/html
    creating build/lib.linux-aarch64-3.6/lxml/isoschematron
    copying src/lxml/isoschematron/__init__.py -> build/lib.linux-aarch64-3.6/lxml/isoschematron
    copying src/lxml/etree.h -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/etree_api.h -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/lxml.etree.h -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/lxml.etree_api.h -> build/lib.linux-aarch64-3.6/lxml
    copying src/lxml/includes/dtdvalid.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xmlparser.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xmlschema.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/schematron.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/__init__.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xmlerror.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xpath.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/uri.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/etreepublic.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/config.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/relaxng.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/tree.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xinclude.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/htmlparser.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/xslt.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/c14n.pxd -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/lxml-version.h -> build/lib.linux-aarch64-3.6/lxml/includes
    copying src/lxml/includes/etree_defs.h -> build/lib.linux-aarch64-3.6/lxml/includes
    creating build/lib.linux-aarch64-3.6/lxml/isoschematron/resources
    creating build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/rng
    copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/rng
    creating build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl
    copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl
    creating build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-aarch64-3.6/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
    running build_ext
    building 'lxml.etree' extension
    creating build/temp.linux-aarch64-3.6
    creating build/temp.linux-aarch64-3.6/src
    creating build/temp.linux-aarch64-3.6/src/lxml
    aarch64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrc/lxml/includes -I/usr/include/python3.6m -I/home/pyimagesearch/.virtualenvs/py3cv4/include/python3.6m -c src/lxml/etree.c -o build/temp.linux-aarch64-3.6/src/lxml/etree.o -w
    In file included from src/lxml/etree.c:692:0:
    src/lxml/includes/etree_defs.h:14:10: fatal error: libxml/xmlversion.h: No such file or directory
     #include "libxml/xmlversion.h"
              ^~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    Compile failed: command 'aarch64-linux-gnu-gcc' failed with exit status 1
    creating tmp
    cc -I/usr/include/libxml2 -c /tmp/xmlXPathInitpm4dvm8o.c -o tmp/xmlXPathInitpm4dvm8o.o
    /tmp/xmlXPathInitpm4dvm8o.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
     main (int argc, char **argv) {
     ^~~~
    cc tmp/xmlXPathInitpm4dvm8o.o -lxml2 -o a.out
    error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/pyimagesearch/.virtualenvs/py3cv4/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hdz59_f3/lxml/setup.py'"'"'; __file__='"'"'/tmp/pip-install-hdz59_f3/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 /tmp/pip-record-9rvpxls3/install-record.txt --single-version-externally-managed --compile --install-headers /home/pyimagesearch/.virtualenvs/py3cv4/include/site/python3.6/lxml Check the logs for full command output.

I haven’t tried that particular install, but this is key:

WARNING: Building wheel for lxml failed: [Errno 13] Permission denied:

Somewhere within the list of content in that line permission did not exist as the user you were running as. This is a specific location:

/home/pyimagesearch/.cache/pip/wheels/73'

If you run as the user you tried the command as, can you:

cd /home/pyimagesearch/.cache/pip/wheels/73'

You might try this:

sudo apt-get install libxml2-dev libxslt1-dev cython3

…and then retry the build. That should fix the dependency problem and the complaing about missing cython. When you create the venv, yuo may need to include the system python packages, or pip install cython from within your venv. Many python packages are much slower without Cython.