Termuxlxml

Termux 安装 Python lxml 库

Termux中安装Python后,为了尝试在手机上测试爬虫,尝试安装PyQuery库,在安装依赖lxml库时报错。

部分错误信息如下:

1
2
3
4
5
Complete output (113 lines):
Building lxml version 4.5.0.
Building without Cython.
ERROR: b'/data/data/com.termux/files/usr/bin/sh: 1: xslt-config: not found\n'
** make sure the development packages of libxml2 and libxslt are installed **

从报错内容可知依赖库libxml2libxslt未安装,通过pkg安装依赖:

1
pkg install libxml2 libxslt

安装完成后再次尝试pip install lxml,再次报错。部分错误信息如下:

1
2
3
4
5
6
7
running build_ext
building 'lxml.etree' extension
creating build/temp.linux-aarch64-3.8
creating build/temp.linux-aarch64-3.8/src
creating build/temp.linux-aarch64-3.8/src/lxml
aarch64-linux-android-clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Oz -fstack-protector-strong -Oz -fstack-protector-strong -fPIC -DCYTHON_CLINE_IN_TRACEBACK=0 -I/data/data/com.termux/files/usr/include/libxml2 -I/data/data/com.termux/files/usr/include -Isrc -Isrc/lxml/includes -I/data/data/com.termux/files/usr/include/python3.8 -c src/lxml/etree.c -o build/temp.linux-aarch64-3.8/src/lxml/etree.o -w
unable to execute 'aarch64-linux-android-clang': No such file or directory

从报错内容可知编译器clang未安装,通过pkg install clang安装后测试安装:

1
2
3
4
5
$ gcc -v
clang version 9.0.0 (tags/RELEASE_900/final)
Target: aarch64-unknown-linux-android
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin

此时使用安装 lxml 和 PyQuery 均不再报错。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ pip install lxml
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting lxml
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/39/2b/0a66d5436f237aff76b91e68b4d8c041d145ad0a2cdeefe2c42f76ba2857/lxml-4.5.0.tar.gz (4.5 MB)
Installing collected packages: lxml
Running setup.py install for lxml ... done
Successfully installed lxml-4.5.0
$ pip install pyquery
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pyquery
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/78/43/95d42e386c61cb639d1a0b94f0c0b9f0b7d6b981ad3c043a836c8b5bc68b/pyquery-1.4.1-py2.py3-none-any.whl (22 kB)
Requirement already satisfied: lxml>=2.1 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from pyquery) (4.5.0)
Requirement already satisfied: cssselect>0.7.9 in /data/data/com.termux/files/usr/lib/python3.8/site-packages (from pyquery) (1.1.0)
Installing collected packages: pyquery
Successfully installed pyquery-1.4.1

同时在Python中测试导入PyQuery正常:

1
2
3
4
5
6
$ python
Python 3.8.0 (default, Dec 5 2019, 10:53:43)
[Clang 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf6 on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyquery import PyQuery as pq
>>>

Termux: 0.83 (Google Play)
Python: 3.8.0
pip: 20.0.2
Andriod: 6.0.1


  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2020 canglan
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~