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

最近在看一个自动化测试框架的问题,需要用到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()
时间: 2024-10-09 23:33:34

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

macOS下Python多版本控制软件的安装:pyenv、pyenv-virtualenv

软件简介: pyenv,是一款特别好用的Python版本管理器,程序员可以建立不同的目录,在不同的目录里分别运行不同版本的Python, 并且互不影响,安装的包也互不影响.github项目地址:https://github.com/yyuu/pyenv pyenv-virtualenv, 是pyenv的一个plugin(插件),可以用来创建基于不同Python版本的干净的虚拟环境.github项目地址:https://github.com/yyuu/pyenv-virtualenv 安装思路:先

Windows下Python安装numpy+mkl,Scipy和statsmodels

最近做时间序列分析需要用到Python中的statsmodels,但是安装过程中遇到很头疼的问题,Google.Stackover各种都没有找到合适的解决办法,而且貌似还有很多同学也在吐槽Windows下Python安装Scipy一团糟,所以有必要分享一下,帮助大家避开此坑. 一般来说,在Python中进行科学计算,numpy和pandas是必不可少的,pandas也依赖于numpy.如果安装了pip的话,直接pip install numpy就可以安装,但是scipy依赖于numpy+mkl,

EnvironmentError: mysql_config not found问题解决(centos7下python安装mysql-python)

centos7下python安装mysql-python模块,执行命令: pip install mysql-python 出现报错:EnvironmentError: mysql_config not found 网上查了一下需安装mysql-devel yum -y install mysql-devel 安装成功后,执行命令python setup.py install 又出现报错:error: command 'gcc' failed with exit status 1 明明装了gcc

windows(32位 64位)下python安装mysqldb模块

windows(32位 64位)下python安装mysqldb模块 www.111cn.net 编辑:mengchu9 来源:转载 本文章来给各位使用在此windows系统中的python来安装一个mysqldb模块教程,有需要了解学习的朋友可参考参考. 1.exe下载地址:http://www.codegood.com/archives/129 分为32位和64位,下载对应的exe即可 2.下载完后,双击exe安装即可 3.检查是否安装成功:如果安装成功,将没有任何提示,如下  代码如下 复

windows下python安装paramiko模块和pycrypto模块(简单三步)

前言 Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,而paramiko模块又依赖于pycrypto模块,因此要在python中使用SSH,我们需要先安装pycrypto模块,然后再安装paramiko模块.下面话不多说了,来一起看看详细的介绍: 安装方法 1>首先要确保python安装好,且环境变量设置好.(关于python的安装,本文不再赘述.) 2>安装pycrypto: 到下面这个网站下载编译好的pycrypto(也可以自己到官网下载pycr

mac下python安装和scrapy安装

mac自带python和pip等工具,但是在使用安装scrapy时,报了一些错,因为对操作系统一些核心目录(比如/Library)没有可操作权限,mac有自己的一些权限控制程序(非sudo chmod能改变),所以干脆重新安装python,这样新安装的python就会在/usr目录里面,而不是系统自带的/Library下面./usr下面是我们有任何权限操作的. 1.我是利用homebrew的方法来安装,当然,也可以直接登录python官网下载安装,个人安装喜好. 2.执行brew install

windows下python安装scrapy碰到的坑

1,提示没有找到vcvarsall.bat文件 确保安装了vs.我这边是win10系统,安装了vs2015,安装的时候要注意,自定义安装项,勾选上"编程语言"里面的库文件和python库支持 2,提示openssl的某个.h文件找不到 去openssl官网下载源码包,解压,把"openssl"整个目录扔到你的python安装目录的include里 3,提示lxml的某些文件找不到 http://www.lfd.uci.edu/~gohlke/pythonlibs/#

Linux下python安装升级详细步骤 | Python2 升级 Python3 转载

Linux下python升级步骤  Python2 ->Python3 多数情况下,系统自动的Python版本是2.x 或者yum直接安装的也是2.x 但是,现在多数情况下建议使用3.x 那么如何升级呢? 下面老徐详细讲解升级步骤: 首先下载源tar包 可利用linux自带下载工具wget下载,如下所示: wget http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz 下载完成后到下载目录下,解压 tar -xzvf Python-3.3

window下python安装pip

python3.5 1.cmd下运行python -m pip install -U pip 2.Path添加python安装目录下的\Scripts,有pip.exe文件 3.重新打开cmd,运行pip list,查看已安装扩展.