【问题标题】:pip install lxml error [closed]pip install lxml错误[关闭]
【发布时间】:2016-07-01 06:46:31
【问题描述】:

我知道这个问题被问了很多次。我已经尝试了所有已知的食谱,但仍然有问题。

所以,我创造了清晰的环境。然后pip install lxml报错:

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/libxml2 -Isrc/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

In file included from src/lxml/lxml.etree.c:85:0:

/usr/include/python2.7/Python.h:8:22: fatal error: pyconfig.h: No such file or directory

compilation terminated.

Compile failed: command 'x86_64-linux-gnu-gcc' failed with exit status 1

creating tmp

cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitRwrJxg.c -o tmp/xmlXPathInitRwrJxg.o

/tmp/xmlXPathInitRwrJxg.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]

 main (int argc, char **argv) {

 ^

cc tmp/xmlXPathInitRwrJxg.o -lxml2 -o a.out

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /home/andriy/PROJECTS/delete/env/bin/python2 -c "import setuptools, tokenize;__file__='/tmp/pip-build-XHiH0Y/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-zuYS3W-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/andriy/PROJECTS/delete/env/include/site/python2.7 failed with error code 1 in /tmp/pip-build-XHiH0Y/lxml
Traceback (most recent call last):
  File "/home/andriy/PROJECTS/delete/env/bin/pip", line 11, in <module>
sys.exit(main())
  File "/home/andriy/PROJECTS/delete/env/local/lib/python2.7/site-packages/pip/__init__.py", line 248, in main
    return command.main(cmd_args)
  File "/home/andriy/PROJECTS/delete/env/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 68: ordinal not in range(128)

我应该说我已经在 Python3 环境中成功安装了lxml。此外,我之前已经成功将lxml 包安装到其他环境。但现在出了点问题。

任何想法如何用 Python2.7 解决它?

这是折磨的第二天,我要重新安装我的 Ubuntu。

解决方案

Padraic Cunningham 解决了我的问题。日志直接表明问题是系统中没有文件pyconfig.h引起的。它是python-dev 包的文件。但是,这个包已经安装了。因此,很自然地假设该软件包已损坏,应使用sudo apt-get install --reinstall python-dev libpython2.7-dev 重新安装。此外,libpython2.7-dev 已重新安装。在该文件pyconfig.h 出现在正确位置之后,pip install lxlm 成功安装了lxml 包。

【问题讨论】:

  • 确保您已安装python-dev
  • 那么ls /usr/include/python2.7/ | grep pyconfig 会返回一些东西吗?
  • 是的,它应该在那里,只是为了验证sudo apt-get install libpython2.7-dev
  • omg... 我想,我知道是什么导致了问题。两周前,我试图删除所有 *.pyc 文件。我想,我还删除了名称中包含 pyc 的文件,pyconfig 就是其中之一。
  • 试试sudo apt-get --reinstall install python-dev libpython2.7-dev

标签: python pip virtualenv lxml


【解决方案1】:

你可以试试:

sudo apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev

【讨论】:

  • 已经安装了。
猜你喜欢
  • 1970-01-01
  • 2019-02-19
  • 2015-09-14
  • 2014-08-11
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多