如何在不使用 MacPorts 或 Fink 的情况下在 OS X Leopard 上安装 lxml?
我过去曾多次尝试过此操作并遇到问题。 有没有人有在没有 MacPorts 或 Fink 的情况下在 OS X 上安装 lxml 的方法,并且绝对有效?
最好有完整的 1-2-3 步骤来下载和构建每个依赖项。
I've tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?
Preferably with complete 1-2-3 steps for downloading and building each of the dependencies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
我正在使用 OSX 10.11 El Capitan 和 Homebrew。 使用
pip install lxml
会给我“致命错误:'libxml/xmlversion.h'文件未找到”和“失败,错误代码1”等等。根据 官方网站,我应该使用
STATIC_DEPS=true pip install lxml
(如果需要的话,在 pip 之前添加 sudo ),这解决了我的问题。我运行
brew install libxml2
和brew install libxslt
来安装依赖项,同时进行故障排除。 我不确定这两个命令是否必要。I'm using OSX 10.11 El Capitan and Homebrew. Using
pip install lxml
would give me "fatal error: 'libxml/xmlversion.h' file not found" and "failed with error code 1" blah blah.According to the official website, I should use
STATIC_DEPS=true pip install lxml
(add sudo before pip if you need that), and that solved my problem.I ran
brew install libxml2
andbrew install libxslt
to install the dependencies while troubleshooting. I'm not sure if those two commands are necessary.尝试安装 Cython 并从源安装,easy_install 确实失败。 不过我还没有在我的 mac 上尝试过。
失败的是ports版本并不是那么古老。 您可以看到依赖项,其中一些依赖项必须针对我的 Linux 版本的 lxml 进行更新。
信息 py25-lxml
py25-lxml @2.1.5 (python, devel)
lxml 是 libxml2 和 libxslt 库的 Pythonic 绑定。 它是独一无二的
因为它结合了这些库的速度和功能完整性
原生 Python API 的简单性,大部分兼容但优于
著名的 ElementTree API。
主页:http://codespeak.net/lxml/
库依赖项:python25、libxml2、libxslt、py25- hashlib、py25-setuptools、
py25-zlib
平台:达尔文
维护者: [电子邮件受保护] [电子邮件受保护]
Try installing Cython and installing from source, easy_install does fail. I haven't tried on my mac yet though.
Failing that the ports version isn't that ancient. You can see the dependencies, some of which had to be updated for my Linux build of lxml.
info py25-lxml
py25-lxml @2.1.5 (python, devel)
lxml is a Pythonic binding for the libxml2 and libxslt libraries. It is unique
in that it combines the speed and feature completeness of these libraries with
the simplicity of a native Python API, mostly compatible but superior to the
well-known ElementTree API.
Homepage: http://codespeak.net/lxml/
Library Dependencies: python25, libxml2, libxslt, py25-hashlib, py25-setuptools,
py25-zlib
Platforms: darwin
Maintainers: [email protected] [email protected]
我在
/usr/local
中编译它,没有任何问题。安装 Python、libxml2、libxslt,然后安装 lxml。 您可能还需要安装 setuptools。
I compile it in
/usr/local
without any issues whatsoever.Install Python, libxml2, libxslt and then lxml. You might need setuptools installed too.
对于过时的 10.6.8 os x 来说,这会带来很多痛苦,但对于任何运行 Snow Leopard 的人来说都是如此!
首先,您必须安装与 homebrew 不同版本的 libxml2 并安装 --with-python。 您可以通过输入以下命令来完成此操作。
然后找到“--without-python”行并更改为“--with-python”。
现在您可以安装 libxml2。
接下来检查默认自制程序位置中新安装的 libxml2。 您想要找到 libxml2 配置。
您的配置可能有所不同:
"/usr/local/Cellar/libxml2/VERSION_/bin/xml2-现在
使用以下命令使用新安装的 libxml2 配置而不是 Mac OS X 版本通过 pip 安装 lxml。
在我的 10.6.8 Python 2.6 上为我工作。 谢谢。
感谢此页面向我展示了 pip --install-option ...
http://natanyellin.com/page/4/
A lot of pain went into this for an outdated 10.6.8 os x but here it goes for anyone running Snow Leopard!
First you have to install a different version of libxml2 from homebrew and install --with-python. You can do this by typing in the following commands.
Then find the line that says "--without-python" and change to "--with-python".
Now you can install libxml2.
Next check your new install of libxml2 in the default homebrew location. You want to find the libxml2 config.
YOURS MAY BE DIFFERENT:
"/usr/local/Cellar/libxml2/VERSION_/bin/xml2-config"
Now use the following command to install lxml with pip using the newly installed libxml2 config and not the Mac OS X version.
Worked for me on my 10.6.8 Python 2.6. Thanks.
Credit goes to this page for showing me pip --install-option ...
http://natanyellin.com/page/4/
要安装最新版本的 libxml2 和 libxslt:
要安装特定版本的库:
CentOS 64 位(有点问题,但来之不易):
或
To install with up to date versions of libxml2 and libxslt:
To install with specific versions of libraries:
CentOS 64 bit (a bit off question, but hard won):
or
这是最新的 - 2009 年 3 月:http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/< /a>
This is quite up to date - march 2009: http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/
lxml 包含在pypm 存储库:
lxml is included in the pypm repository:
感谢 Twitter 上的 @jessenoller,我得到了一个适合我需求的答案 - 您可以使用静态依赖项编译 lxml,从而避免弄乱 OS X 附带的 libxml2。以下是对我有用的方法:
Thanks to @jessenoller on Twitter I have an answer that fits my needs - you can compile lxml with static dependencies, hence avoiding messing with the libxml2 that ships with OS X. Here's what worked for me:
这对我有用(10.6.8):
This worked for me (10.6.8):
我非常幸运地使用 Homebrew 安装
libxml2
依赖项:Homebrew 没有似乎有
libxslt
可用,但我还不需要 XSLT。 YMMV。一旦有了依赖关系,那么通常的方法就可以正常工作:
或者
I've had excellent luck with Homebrew to install the
libxml2
dependency:Homebrew doesn't seem to have
libxslt
available, but I've not yet had a need for XSLT. YMMV.Once you have the dependency(s), then the usual methods work just fine:
or
Easy_install可以使用以下命令:
STATIC_DEPS=true easy_install 'lxml>=2.2beta4'
您可能然后需要运行,具体取决于权限;
STATIC_DEPS=true sudo easy_install 'lxml>=2.2beta4'
参见
http://muffinresearch.co.uk/archives/ 2009/03/05/安装-lxml-on-osx/
Easy_install can work using this:
STATIC_DEPS=true easy_install 'lxml>=2.2beta4'
you may then need to run, depending on permissions;
STATIC_DEPS=true sudo easy_install 'lxml>=2.2beta4'
see
http://muffinresearch.co.uk/archives/2009/03/05/install-lxml-on-osx/
在 el Captain (10.11.1) 上使用自制程序 (0.9.5) 以下内容对我有用:
using homebrew (0.9.5) on el capitan (10.11.1) the following worked for me:
这对我有用 10.8.5
brew install libxml2
这包括以下建议:
但我想将其编译成一个答案,而不是到处留下评论
This worked for me on 10.8.5
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew install libxml2
sudo easy_install lxml
This comprises suggestions from:
But I wanted to compile it into one answer rather than leave comments everywhere
在 OS X 10.9.1 上,上述建议答案在安装过程中出错 - 必须进行以下更改:
On OS X 10.9.1 the suggested answer above errors out during install -- following changes had to be made:
我在 Snow Lepoard 上工作得很好,但在升级到 Lion 后,我必须将 gcc-4.2 符号链接到 gcc。 运行 sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml 正在寻找 gcc-4.2 而不是 gcc。
I had this working fine with Snow Lepoard but after I upgraded to Lion I had to symlink gcc-4.2 to gcc. Running sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml was looking for gcc-4.2 instead of gcc.