如何在不使用 MacPorts 或 Fink 的情况下在 OS X Leopard 上安装 lxml?

发布于 2024-08-01 19:22:32 字数 122 浏览 5 评论 0原文

我过去曾多次尝试过此操作并遇到问题。 有没有人有在没有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

夜深人未静 2024-08-08 19:22:33

我正在使用 OSX 10.11 El Capitan 和 Homebrew。 使用pip install lxml会给我“致命错误:'libxml/xmlversion.h'文件未找到”和“失败,错误代码1”等等。

根据 官方网站,我应该使用 STATIC_DEPS=true pip install lxml (如果需要的话,在 pip 之前添加 sudo ),这解决了我的问题。

我运行 brew install libxml2brew 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 and brew install libxslt to install the dependencies while troubleshooting. I'm not sure if those two commands are necessary.

强辩 2024-08-08 19:22:33

尝试安装 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]

唯憾梦倾城 2024-08-08 19:22:33

我在 /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.

两个我 2024-08-08 19:22:33

对于过时的 10.6.8 os x 来说,这会带来很多痛苦,但对于任何运行 Snow Leopard 的人来说都是如此!

首先,您必须安装与 homebrew 不同版本的 libxml2 并安装 --with-python。 您可以通过输入以下命令来完成此操作。

brew update
brew edit libxml2

然后找到“--without-python”行并更改为“--with-python”。

system "./configure", "--disable-dependency-tracking",
                      "--prefix=#{prefix}",
                      "--with-python"

现在您可以安装 libxml2。

brew install libxml2

接下来检查默认自制程序位置中新安装的 libxml2。 您想要找到 libxml2 配置。

您的配置可能有所不同:

"/usr/local/Cellar/libxml2/VERSION_/bin/xml2-现在

使用以下命令使用新安装的 libxml2 配置而不是 Mac OS X 版本通过 pip 安装 lxml。

ARCHFLAGS="-arch i386 -arch x86_64" pip install lxml --install-option="--with-xml2-config=/usr/local/Cellar/libxml2/2.9.1/bin/xml2-config"

在我的 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.

brew update
brew edit libxml2

Then find the line that says "--without-python" and change to "--with-python".

system "./configure", "--disable-dependency-tracking",
                      "--prefix=#{prefix}",
                      "--with-python"

Now you can install libxml2.

brew 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.

ARCHFLAGS="-arch i386 -arch x86_64" pip install lxml --install-option="--with-xml2-config=/usr/local/Cellar/libxml2/2.9.1/bin/xml2-config"

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/

心作怪 2024-08-08 19:22:33

要安装最新版本的 libxml2 和 libxslt:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml

要安装特定版本的库:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml

CentOS 64 位(有点问题,但来之不易):

CFLAGS=-fPIC STATIC_DEPS=true pip install lxml

CFLAGS=-fPIC STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml

To install with up to date versions of libxml2 and libxslt:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml

To install with specific versions of libraries:

ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml

CentOS 64 bit (a bit off question, but hard won):

CFLAGS=-fPIC STATIC_DEPS=true pip install lxml

or

CFLAGS=-fPIC STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml
我乃一代侩神 2024-08-08 19:22:33

lxml 包含pypm 存储库:

$ pypm install lxml

lxml is included in the pypm repository:

$ pypm install lxml
薄暮涼年 2024-08-08 19:22:32

感谢 Twitter 上的 @jessenoller,我得到了一个适合我需求的答案 - 您可以使用静态依赖项编译 lxml,从而避免弄乱 OS X 附带的 libxml2。以下是对我有用的方法:

cd /tmp
curl -O http://lxml.de/files/lxml-3.6.0.tgz
tar -xzvf lxml-3.6.0.tgz 
cd lxml-3.6.0
python setup.py build --static-deps --libxml2-version=2.7.3  --libxslt-version=1.1.24 
sudo python setup.py install

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:

cd /tmp
curl -O http://lxml.de/files/lxml-3.6.0.tgz
tar -xzvf lxml-3.6.0.tgz 
cd lxml-3.6.0
python setup.py build --static-deps --libxml2-version=2.7.3  --libxslt-version=1.1.24 
sudo python setup.py install
老子叫无熙 2024-08-08 19:22:32

这对我有用(10.6.8):

sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml

This worked for me (10.6.8):

sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml
×眷恋的温暖 2024-08-08 19:22:32

我非常幸运地使用 Homebrew 安装 libxml2 依赖项:

brew install libxml2

Homebrew 没有似乎有 libxslt 可用,但我还不需要 XSLT。 YMMV。

一旦有了依赖关系,那么通常的方法就可以正常工作:

pip install lxml

或者

easy_install lxml

I've had excellent luck with Homebrew to install the libxml2 dependency:

brew install libxml2

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:

pip install lxml

or

easy_install lxml
蔚蓝源自深海 2024-08-08 19:22:32

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/

败给现实 2024-08-08 19:22:32

在 el Captain (10.11.1) 上使用自制程序 (0.9.5) 以下内容对我有用:

brew install libxml2
LD_FLAGS=-L/usr/local/opt/libxml2/lib CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 pip install lxml

using homebrew (0.9.5) on el capitan (10.11.1) the following worked for me:

brew install libxml2
LD_FLAGS=-L/usr/local/opt/libxml2/lib CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 pip install lxml
北恋 2024-08-08 19:22:32

这对我有用 10.8.5

  1. Install Xcode from Mac App Store
  2. Xcode -> 首选项-> 下载-> 命令行工具
  3. 使用
  4. ruby​​ -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  5. 安装 homebrew brew install libxml2
  6. < code>sudo easy_install lxml

这包括以下建议:

但我想将其编译成一个答案,而不是到处留下评论

This worked for me on 10.8.5

  1. Install Xcode from Mac App Store
  2. Xcode -> Preferences -> Downloads -> Command Line Tools
  3. Install homebrew using
  4. ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  5. brew install libxml2
  6. sudo easy_install lxml

This comprises suggestions from:

But I wanted to compile it into one answer rather than leave comments everywhere

筱果果 2024-08-08 19:22:32

OS X 10.9.1 上,上述建议答案在安装过程中出错 - 必须进行以下更改:

cd /tmp  
curl -o lxml-3.3.0.tgz http://lxml.de/files/lxml-3.3.0.tgz  
tar -xzvf lxml-3.3.0.tgz  
cd lxml-3.3.0  
python setup.py build --static-deps --libxml2-version=2.8.0  --libxslt-version=1.1.24  
sudo python setup.py install  

On OS X 10.9.1 the suggested answer above errors out during install -- following changes had to be made:

cd /tmp  
curl -o lxml-3.3.0.tgz http://lxml.de/files/lxml-3.3.0.tgz  
tar -xzvf lxml-3.3.0.tgz  
cd lxml-3.3.0  
python setup.py build --static-deps --libxml2-version=2.8.0  --libxslt-version=1.1.24  
sudo python setup.py install  
安静 2024-08-08 19:22:32

我在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文