Recently looking at an automated testing framework of the problem, need to use the lxml library, download lxml always error.
1, install lxml using PIP
Pip Install lxml
2, and then error, the error content is:
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, then Baidu has n long N long, borrowed from a great God's plan, http://blog.marchtea.com/archives/91
4, find into Application->xcode, right-click: display Content , follow the following code path step by step: Copy path:/applications/xcode.app/contents/ Developer/platforms/macosx.platform/developer/sdks/macosx10.9.sdk/usr/include
Then enter in the terminal:
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, then use PIP to install again
Pip Install lxml
6, see the Success!!!
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:l xmlrunning 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-s Trict-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-w All-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/te Mp.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, for insurance, and then test it:
Cindy-macdemacbook-pro:users cindy_mac$ Pythonpython 2.7.5 (default, MAR9, 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 installation lxml error Xmlversion.h not found error solution in MacOS