在MacOS下Python安装lxml报错xmlversion.h not found 报错的解决方案

简介: 最近在看一个自动化测试框架的问题,需要用到Lxml库,下载lxml总是报错。 1,使用pip安装lxml pip install lxml 2,然后报错了,报错内容是: In file included from src/lxml/lxml.

最近在看一个自动化测试框架的问题,需要用到Lxml库,下载lxml总是报错。

1,使用pip安装lxml

pip install lxml

2,然后报错了,报错内容是:

In file included from src/lxml/lxml.etree.c:139:src/lxml/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found#include "libxml/xmlversion.h"	^1 error generated.error: command 'cc' failed with exit status 1----------------------------------------Cleaning up...Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip_build_cindy_mac/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('/r/n', '/n'), __file__, 'exec'))" install --record /var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip-xwdVzY-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip_build_cindy_mac/lxmlStoring debug log for failure in /Users/cindy_mac/Library/Logs/pip.log

3,然后百度了N久N久,借鉴了一个大神的方案,http://blog.marchtea.com/archives/91

4,找到进入Application->XCode,右键选择:显示内容,按照下面代码的路径一步一步往下跟:复制路径:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include

然后在终端输入:

C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include

5,然后再次使用pip安装

pip install lxml

6,看到成功了!!!

Downloading/unpacking lxmlDownloading lxml-3.4.1.tar.gz (3.5MB): 3.5MB downloadedRunning setup.py (path:/private/var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip_build_cindy_mac/lxml/setup.py) egg_info for package lxml/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'warnings.warn(msg)Building lxml version 3.4.1.Building without Cython.Using build configuration of libxslt 1.1.28warning: no previously-included files found matching '*.py'Installing collected packages: lxmlRunning setup.py install for lxml/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'warnings.warn(msg)Building lxml version 3.4.1.Building without Cython.Using build configuration of libxslt 1.1.28building 'lxml.etree' extensioncc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/usr/include/libxml2 -I/private/var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip_build_cindy_mac/lxml/src/lxml/includes -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.9-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespacecc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/lxml/lxml.etree.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.9-intel-2.7/lxml/etree.sobuilding 'lxml.objectify' extensioncc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/usr/include/libxml2 -I/private/var/folders/rc/0lpvj1710n332qg8p2wgcqyr0000gn/T/pip_build_cindy_mac/lxml/src/lxml/includes -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.objectify.c -o build/temp.macosx-10.9-intel-2.7/src/lxml/lxml.objectify.o -w -flat_namespacecc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/lxml/lxml.objectify.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.9-intel-2.7/lxml/objectify.soSuccessfully installed lxmlCleaning up...

7,为了保险,然后测试一下:

Cindy-macdeMacBook-Pro:Users cindy_mac$ pythonPython 2.7.5 (default, Mar9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import lxml>>> exit()
技术改变世界! --狂诗绝剑
目录
相关文章
|
1月前
|
关系型数据库 MySQL Python
python安装MySQL-python:EnvironmentError解决办法
python安装MySQL-python:EnvironmentError解决办法
31 1
|
30天前
|
Java Python 开发者
Python 学习之路 01基础入门---【Python安装,Python程序基本组成】
线程池详解与异步任务编排使用案例-xian-cheng-chi-xiang-jie-yu-yi-bu-ren-wu-bian-pai-shi-yong-an-li
78 2
Python 学习之路 01基础入门---【Python安装,Python程序基本组成】
|
2天前
安装OpenCV-Python
安装OpenCV-Python
11 1
|
3天前
|
5G Python
Windows11搭建Python环境(Anaconda安装与使用)
Windows11搭建Python环境(Anaconda安装与使用)
19 0
|
10天前
|
Python
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
|
15天前
|
JavaScript 前端开发 关系型数据库
金融技术解决方案:用Python和Vue开发加密货币交易平台
【4月更文挑战第11天】本文介绍了如何使用Python和Vue.js构建加密货币交易平台。首先确保安装了Python、Node.js、数据库系统和Git。后端可选择Flask或Django框架,通过RESTful API处理交易。前端利用Vue.js、Vuex和Vue Router创建用户友好的界面,并用Axios与后端通信。这种架构促进团队协作,提升代码质量和平台功能。
|
16天前
|
Ubuntu Python
python3安装clickhouse_sqlalchemy(greenlet) 失败
如果上述方法仍然无法解决问题,建议查阅相关错误信息和官方文档,以获取更详细的帮助。确保你的Python环境和依赖库都在最新版本,有时问题可能会因为版本不兼容而导致安装失败。
18 0
|
18天前
|
数据采集 自然语言处理 搜索推荐
一篇博客带你领略学习Python的第三方库---如何获取和安装第三方库,关于三种常见第三方库的下载和讲解(pyinstall库,jieba库,wordcloud库),更多第三方库的分类介绍
一篇博客带你领略学习Python的第三方库---如何获取和安装第三方库,关于三种常见第三方库的下载和讲解(pyinstall库,jieba库,wordcloud库),更多第三方库的分类介绍
|
19天前
|
数据采集 机器学习/深度学习 人工智能
Python环境搭建—安装Python3解释器
Python环境搭建—安装Python3解释器
34 2
|
19天前
|
数据采集 JavaScript C++
Python搭建编程环境-安装Python3解释器
Python搭建编程环境-安装Python3解释器
24 1