无法使用pip安装lxml。
无法使用pip安装lxml。
我尝试在Ubuntu 14.04上使用pip install lxml
命令安装lxml Python库。
但是安装失败了,输出结果如下(只列出了最后部分):
... ... ... src/lxml/lxml.etree.c:8:22: 致命错误: pyconfig.h: 没有那个文件或目录 #include "pyconfig.h" ^ 编译已终止。 错误: 命令 'x86_64-linux-gnu-gcc' 以退出状态 1 失败
我搜索了一下问题,并发现应该使用以下命令安装一些东西:
apt-get install libxml2-dev libxslt-dev libxslt1-dev python-dev
然后我尝试再次使用pip install lxml
命令安装。但是安装再次失败,这次出现了另一个错误。尝试使用pip --default-timeout=300 install lxml
也没有改变。
新的错误如下:
... ... ... creating build/temp.linux-x86_64-2.7/src/lxml x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/tmp/pip_build_root/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.linux-x86_64-2.7/lxml/etree.so /usr/bin/ld: 无法找到 -lz collect2: 错误:ld 返回 1 退出状态 错误: 命令 'x86_64-linux-gnu-gcc' 以退出状态 1 失败 ---------------------------------------- 清理... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-PVygtI-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml 失败信息存储在 /root/.pip/pip.log 文件中
从/root/.pip/pip.log
文件中获取的其他信息如下:
异常信息: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run requirement_set.install(install_options, global_options, root=options.root_path) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install requirement.install(install_options, global_options, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/pip/req.py", line 707, in install cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False) File "/usr/lib/python2.7/dist-packages/pip/util.py", line 715, in call_subprocess % (command_desc, proc.returncode, cwd)) InstallationError: Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Jj2y9w-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/lxml
然而,我可以通过apt-get install python-lxml
命令安装lxml,也可以在从lxml网站手动下载后进行本地安装,但我想使用pip进行安装。