Homebrew 安装 libxml2 和 python 模块

问题描述 投票:0回答:5

早上好,

我正在尝试使用 python 模块安装 libxml2。我尝试过以下方法:

brew install --with-python libxml2                                                                  
==> Downloading ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz
Already downloaded: /Users/brandon/Library/Caches/Homebrew/libxml2-2.8.0.tar.gz
==> ./configure --prefix=/usr/local/Cellar/libxml2/2.8.0 --without-python

正如你所看到的...即使使用 --with-python 标志,它仍然在不使用 python 的情况下配置源!

安装结束时,自制软件会说:

Generally there are no consequences of this for you.
If you build your own software and it requires this formula, you'll need
to add its lib & include paths to your build variables:

    LDFLAGS  -L/usr/local/Cellar/libxml2/2.8.0/lib
    CPPFLAGS -I/usr/local/Cellar/libxml2/2.8.0/include

当我尝试安装 gnome-doc-utils 软件包时:

Gnome-doc-utils requires libxml2 to be compiled
with the python modules enabled, to do so:
  $ brew install libxml2 --with-python

很明显我又试了一次......

╰─ brew install libxml2 --with-python
Error: libxml2-2.8.0 already installed

我对此仍然陌生......所以任何帮助将不胜感激。

python macos libxml2 homebrew
5个回答
19
投票

首先,您无法安装libxml2,因为您已经成功安装了它,因此您首先需要卸载它。

brew uninstall libxml2

接下来您需要编辑冲泡公式 - 这很简单 --

类型

brew edit libxml2
并更改线路

system "./configure", "--prefix=#{prefix}", "--without-python"

对此:

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

这并不能解决brew公式的问题,但它确实会强制使用“--with-python”标志,因此下次您输入

brew install libxml2
时,它将安装python库。

如果您需要重置公式(撤消更改),只需键入

brew update


8
投票

这对我有用。如果之前已完成,请首先取消链接/卸载:

brew unlink libxml2
brew unlink libxslt
brew uninstall libxml2
brew uninstall libxslt

然后

brew install --framework python
brew install --with-python libxml2
brew install --with-python libxslt
brew link libxml2 --force
brew link libxslt --force

瞧!


3
投票

有效的是在brew命令中使用--with-python安装libxml2

brew install --with-python libxml2

1
投票

kylehunt 的答案让我解决了一个问题,该问题是在升级到 macOS Catalina 后运行“brew Upgrade”后开始出现的:

如果你碰巧看到类似的东西

Error: libxml2: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:53: syntax error, unexpected <<
<<<<<<< Updated upstream
^~
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:54: syntax error, unexpected ',', expecting end
...              "--with-history",
...                              ^
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:55: syntax error, unexpected ',', expecting end
...            "--without-python",
...                              ^
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/libxml2.rb:57: syntax error, unexpected ',', expecting end
...               "--with-python",
...

这意味着你应该跑步

brew edit libxml2

修复配置文件,因为它可能在升级过程中因合并冲突而被破坏。寻找<<<<< in the file.


0
投票

就我而言,libxml2 安装正常,但它不在我的 python 导入路径上。像这样编辑我的 PYTHONPATH 后:

export PYTHONPATH=/usr/local/Cellar/libxml2/2.12.4/lib/python3.12/site-packages/

我能够导入 libxml2。

$ python3
>>> import libxml2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'libxml2'
>>> ^D

$ export PYTHONPATH=/usr/local/Cellar/libxml2/2.12.4/lib/python3.12/site-packages
$ python3
>>> import libxml2
>>> 
© www.soinside.com 2019 - 2024. All rights reserved.