相关文章推荐
不羁的面包  ·  Django之自定义 form ...·  4 月前    · 
聪明的啤酒  ·  Dataframe.to_csv(sep=" ...·  1 年前    · 
豁达的帽子  ·  usesCleartextTraffic详解 ...·  1 年前    · 
坚强的罐头  ·  asp.net - How to fix ...·  1 年前    · 
本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《 阿里云开发者社区用户服务协议 》和 《 阿里云开发者社区知识产权保护指引 》。如果您发现本社区中有涉嫌抄袭的内容,填写 侵权投诉表单 进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
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()
技术改变世界! --狂诗绝剑 Python文件路径报错SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: t
这个错误通常出现在Python代码中使用了反斜杠(\)的情况下,反斜杠后跟着一个不合法的Unicode字符编码导致的。这个错误一般发生在Windows系统中,因为在Windows系统中,反斜杠(\)常常用于文件路径的分隔符,而Python中反斜杠也用于转义字符,从而导致了冲突。
游客diar4qdndedt2 如何 python import h5py 报错 :/defs.cpython-37m-x86_64-linux-gnu.so: undefined symbol: H5Pset_fapl_ros3
如何 python import h5py 报错 :/defs.cpython-37m-x86_64-linux-gnu.so: undefined symbol: H5Pset_fapl_ros3
游客rigajubvzf2hs