简体   繁体   English

无法在MacOS 10.8.4中安装lxml

[英]Fail to install lxml in MacOS 10.8.4

I am having trouble installing lxml to my Mac OS. 我在将lxml安装到Mac OS时遇到问题。 I am having the following error when building it. 构建它时出现以下错误。 This is the error I have when using pip install lxml 这是我使用pip install lxml时出现的错误

/private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found /private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml/src/lxml/includes/etree_defs.h:9:10:致命错误:找不到'libxml / xmlversion.h'文件

I have installed libxml2 with brew: 我用brew安装了libxml2:

brew install libxml2
brew link libxml2 --force

I'm new to Mac. 我是Mac的新手。 In Ubuntu, it would mean libxml2-dev package must be installed. 在Ubuntu中,这意味着必须安装libxml2-dev软件包。

Updated: here is the pip.log: 更新:这是pip.log:

"~/.pip/pip.log" 124L, 8293C requirement_set.install(install_options, global_options, root=options.root_path) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1185, in install requirement.install(install_options, global_options, *args, **kwargs) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 592, in install cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/util.py", line 662, in call_subprocess % (command_desc, proc.returncode, cwd)) InstallationError: Command /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools; file ='/private/var/folders/9s/s5hl5w4x7zjdjkdljw “〜/ .pip / pip.log”124L,8293C requirement_set.install(install_options,global_options,root = options.root_path)File“/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/ 2.7 / lib / python2.7 / site-packages / pip-1.3.1-py2.7.egg / pip / req.py“,第1185行,在install requirement.install中(install_options,global_options,* args,** kwargs )文件“/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/ req.py“,第592行,在install cwd = self.source_dir中,filter_stdout = self._filter_install,show_stdout = False)文件”/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7 /lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/util.py“,第662行,在call_subprocess%(command_desc,proc.returncode,cwd)中)InstallationError:Command / usr / local / Cellar / python / 2.7.5 / Frameworks / Python.framework / Versions / 2.7 / Resources / Python.app / Contents / MacOS / Python -c“import setuptools; file ='/ private / var / folders / 9s / s5hl5w4x7zjdjkdljw 9cnsrm0000gn/T/pip-build-khuevu/lxml/setup.py';exec(compile(open( file ).read().replace('\\r\\n', '\\n'), file , 'exec'))" install --record /var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-nsV0iT-record/install-record.txt --single-version-externally-managed failed with error code 1 in /private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml 9cnsrm0000gn / T / pip-build-khuevu / lxml / setup.py'; exec(compile(open( file ).read()。replace('\\ r \\ n','\\ n'), file ,'exec' ))“install --record /var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-nsV0iT-record/install-record.txt --single-version-external-managed failed / private / var / folders中的错误代码1 / 787-9 / s5hl5w4x7zjdjkdljw9cnsrm0000gn / T / PIP-积聚khuevu / LXML

Any idea ? 任何的想法 ? Thanks a lot 非常感谢

Turn out xmlversion.h is not included in compilation path even though it is in PATH. 结果xmlversion.h不包含在编译路径中,即使它在PATH中。 Modify the C_INCLUDE_PATH env fix the error for me: 修改C_INCLUDE_PATH env为我修复错误:

C_INCLUDE_PATH=/usr/local/Cellar/libxml2/2.9.1/include/libxml2:$C_INCLUDE_PATH C_INCLUDE_PATH =在/ usr /本地/库/ libxml2的/ 2.9.1 /包括/ libxml2的:$ C_INCLUDE_PATH

如果您在安装Xcode的情况下运行Mavericks,您还可以使用:

export C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/libxml2:$C_INCLUDE_PATH

None of the other answers (exporting C_INCLUDE_PATH) worked for me. 没有其他答案(导出C_INCLUDE_PATH)对我有用。 However, setting the CFLAGS environment variable to the built-in OS X 10.10 libxml2 root worked like a charm. 但是,将CFLAGS环境变量设置为内置OS X 10.10 libxml2根就像魅力一样。

export CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2

I have Python and libxml installed via brew, this worked for me after trying everything above: 我通过brew安装了Python和libxml,在尝试了以上所有内容后,这对我有用:

sudo mkdir /usr/include # If /usr/include is missing
sudo ln -s /usr/local/Cellar/libxml2/2.9.2/include/libxml2 /usr/include/libxml2

Note: You'll need to check your own paths for latest versions. 注意:您需要检查自己的路径以获取最新版本。

Since the headers are available elsewhere, and being looked for in a particular directory (spotted in the command calling clang to compile) - and for some reason the alternate place is not being picked up, I made a softlink to the right place. 由于标题在别处可用,并且在特定目录中查找(在命令调用clang编译中发现) - 并且由于某种原因,备用位置没有被拾取,我做了一个到正确位置的软链接。

brew install libxml2
brew link libxml2 --force
export C_INCLUDE_PATH=/usr/local/Cellar/libxml2/2.9.2/include/libxml2:$C_INCLUDE_PATH

there is something with the permission to mkdir in /usr/ when the system is Mac EI captain. 当系统是Mac EI队长时, /usr/ mkdir的权限。 Maybe we can not modify this directory? 也许我们不能修改这个目录?

See What is the “rootless” feature in El Capitan, really? 看看El Capitan的“无根”功能是什么? on AskDifferent 在AskDifferent上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM