python - pip 安装 lxml 错误

标签 python pip virtualenv lxml

<分区>

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

所以,我创造了清晰的环境。然后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 包。

最佳答案

你可以试试:

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

关于python - pip 安装 lxml 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36017879/

相关文章:

python - 如何提高sqlite3建表的性能

python - 当应该影响 X 的变量发生变化时,变量 X 不更新

python - 了解移动到不同机器时的虚拟环境行为

python - 使用 genfromtxt 创建具有空列的 numpy 数组

python - 为什么 "G.nodes[1][' key']"has error? TypeError: ' method'对象不可下标

python-3.x - 如何使用 Visual Studio Code 在 vi​​rtualenv 中执行 python 命令

python - 使用 virtualenv 安装 gdal 1.11

Python:PIL/_imaging.so:无效的 ELF header

python - 导入错误 : No module named 'pip._vendor.diSTLib.scripts' when I try to install fabric by python pip

Python安装设置工具出现语法错误