QNAPのNASにPython/lxml環境を構築する
NAS: TS-231
Python:2 or 3
lxml: 3.7.3
numpy/pandasを入れてからしばらく経ちましたが、仕事が忙しくて疲れていたと言い訳をまず書いておきます。
さて、pythonでのスクレイピングに必要になってくるlxmlパッケージをインストールするところでまた躓いたのでメモしておきます。
python2でも3でも、SSH接続して単純に"pip install lxml"するだけではエラーが出るので、"opkg install libxml2 libxslt"などで関連ライブラリをインストールします。
ただし、それでも以下のようなエラーが出ます。
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: No such file or directory
#include "libxml/xmlversion.h"
^
compilation terminated.
Compile failed: command 'arm-openwrt-linux-gnueabi-gcc' failed with exit status 1
cc -I/usr/include/libxml2 -c /opt/tmp/xmlXPathInitg7GyME.c -o opt/tmp/xmlXPathInitg7GyME.o
unable to execute 'cc': No such file or directory
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'arm-openwrt-linux-gnueabi-gcc' failed with exit status 1'''
試しにxmlversion.hを検索してみると、
# find / -name "xmlversion.h"
/share/CACHEDEV1_DATA/.qpkg/Entware-ng/include/libxml2/libxml/xmlversion.h
パスが通ってないっぽいのでしばらくググってみると
Package Request: python27-lxml · Issue #201 · Entware-ng/Entware-ng · GitHub
ここの回答の通り、シンボリックリンクを張ることで解決しました。
ln -s /opt/include/libxml2/libxml/ /opt/include/libxml