Python pip安装lxml错误

Python pip安装lxml错误,python,pip,virtualenv,lxml,Python,Pip,Virtualenv,Lxml,我知道这个问题被问了很多次。我尝试了所有已知的食谱,但仍然有一个问题 所以,我创造了清晰的环境。然后pip安装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 -f

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

所以,我创造了清晰的环境。然后
pip安装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)
x86_64-linux-gnu-gcc-pthread-DNDEBUG-g-fwrapv-O2-Wall-Wstrict原型-fno严格别名-D_-FORTIFY_-SOURCE=2-g-fstack-protector-strong-Wformat-Werror=format-security-fPIC-I/usr/include/libxml2-Isrc/lxml/include-I/usr/python2.7-c src/lxml/lxml/lxml.etree-o build/temp/linux-x86_-64-2.7/2.7/src/lxml/lxml
在src/lxml/lxml.etree.c中包含的文件中:85:0:
/usr/include/python2.7/Python.h:8:22:致命错误:pyconfig.h:没有这样的文件或目录
编译终止。
编译失败:命令“x86_64-linux-gnu-gcc”失败,退出状态为1
创建tmp
cc-I/usr/include/libxml2-I/usr/include/libxml2-c/tmp/xmlXPathInitRwrJxg.c-o tmp/xmlXPathInitRwrJxg.o
/tmp/xmlXPathInitRwrJxg.c:2:1:警告:返回类型默认为“int”[-Wimplicit int]
主(内部argc,字符**argv){
^
cc tmp/xmlxpathinitrjxg.o-lxml2-o a.out
错误:命令“x86_64-linux-gnu-gcc”失败,退出状态为1
----------------------------------------
清理。。。
Command/home/andriy/PROJECTS/delete/env/bin/python2-c“导入设置工具,标记化;_文件_uu=”/tmp/pip-build-XHiH0Y/lxml/setup.py';exec(编译(getattr(标记化,'open',open打开)(_u文件_uu).read().replace('\r\n','n'),_u文件,'exec'))”安装--record/tmp/pip-zuYS3W-record/install-record.txt--外部管理的单一版本--编译--install headers/home/andriy/PROJECTS/delete/env/include/site/python2.7失败,错误代码为/tmp/pip-build-XHiH0Y/lxml中的1
回溯(最近一次呼叫最后一次):
文件“/home/andriy/PROJECTS/delete/env/bin/pip”,第11行,在
sys.exit(main())
文件“/home/andriy/PROJECTS/delete/env/local/lib/python2.7/site packages/pip/_init__.py”,第248行,主目录
return command.main(cmd_args)
文件“/home/andriy/PROJECTS/delete/env/local/lib/python2.7/site-packages/pip/basecommand.py”,第161行,主目录
text='\n'.连接(完成日志)
UnicodeDecodeError:“ascii”编解码器无法解码第68位的字节0xe2:序号不在范围内(128)
我应该说,我已经用Python3在环境中成功地安装了
lxml
。此外,我之前已经成功地将
lxml
包安装到其他环境中。但是现在有些东西坏了

有没有办法用Python2.7解决这个问题

这是痛苦的第二天,我即将重新安装我的Ubuntu

解决方案


下面的Padraic Cunningham解决了我的问题。日志直接表明问题是由于系统中缺少文件
pyconfig.h
造成的。它是
python dev
包的文件。但是,该包已经安装。因此,很自然地假设该包是腐蚀程序,应该是rei安装了
sudo apt get install——重新安装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 dev
so
ls/usr/include/python2.7/| grep pyconfig
返回了什么?是的,它应该在那里,只是为了验证
sudo apt get install libpython2.7-dev
omg…我想,我知道是什么导致了这个问题问题。两周前,我试图删除所有
*.pyc
文件。我想,我也删除了名称中包含
pyc
的文件,
pyconfig
就是其中之一。尝试
sudo apt get——重新安装已经安装的python dev libpython2.7-dev