有没有办法在 python 构建中包含brew注入?

发布于 2025-01-16 10:43:39 字数 210 浏览 1 评论 0原文

我正在尝试构建一个在浏览器中运行的语音识别应用程序。目前正在与网络工作者一起使用 pyodide。我有自己的包,与 pyaudio 一起构建,用于网络工作人员。

有没有一种方法可以让我在 python 包中包含一个brew注入,特别是portaudio,这样当我构建包时,portaudio就包含在wheel文件中?我需要包含 portaudio 才能在浏览器中工作。

谢谢你!

I'm trying to build a speech recognition application that works in a browser. Currently using pyodide with a web worker. I have my own package, built alongside pyaudio, that I use for the web worker.

Is there a way that I can include a brew instillation, specifically portaudio, inside of my python package so that when I build the package, portaudio is included in the wheel file? I need portaudio included for this to work in the browser.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

岁月蹉跎了容颜 2025-01-23 10:43:39

我在这里理解两个不同的问题,所以我会尝试回答这两个问题。

我可以让 python 构建在构建期间获取 Homebrew 项目吗

据我所知,答案是否定的。 Python 分发系统与 Homebrew 是分开的,它们不能以这种方式交互。

即使他们可以,这也不一定是可取的:

  • 如果用户不在 macOS(或 Linux)上会发生什么?那么构建就会失败。
  • Homebrew 将安装包的前缀并不是很确定。用户可能使用自定义前缀,也可能使用 Apple Silicon(其默认前缀与 Intel 不同)。
    • 您的 python 包在查找包时可能会遇到一些困难。
  • 如果他们没有安装 Homebrew 怎么办?他们可能有另一个包管理器,例如 MacPorts 或 Fink,或者根本没有。

我可以将 portaudio 捆绑到构建发行版中吗?

或许?即使你可以,我几乎肯定不会推荐它。

  • 捆绑依赖性会不必要地增加发行版的大小。
  • 假设您可以做到,那么设置需要花费一定的精力。

所有这些原因就是为什么对于大多数具有类似设置的项目,您会发现他们建议在构建 Python 源代码之前先使用系统包管理器安装某些包。

这允许他们选择他们安装的任何包管理器,并且这也应该是一个快速且轻松的过程。

因此,只需将安装说明更改为以下内容:

# On macOS
brew install portaudio
pip install ...

I'm understanding two different questions here, so I'll try to answer them both.

Can I have a python build fetch a Homebrew project during buildtime

To my knowledge, the answer is no. The Python distribution system is separate from Homebrew, and they can't interact in this fashion.

Even if they could, this wouldn't necessarily be desirable:

  • What happens if the user isn't on macOS (or Linux)? Then the build would fail.
  • The prefix that Homebrew will install the package in isn't very deterministic. The user might be using a custom prefix, or they might be on Apple Silicon (which has a different default prefix to Intel).
    • Your python package might run into some difficulty locating the package.
  • What about if they don't have Homebrew installed? They might have another package manager like MacPorts or Fink, or maybe none at all.

Can I bundle portaudio into the build distribution?

Maybe? Even if you could, I almost certainly wouldn't recommend it.

  • Bundling dependencies increases the size of the distribution unnecessarily.
  • It would take a reasonable amount of effort to setup, assuming you can do it.

All these reasons are why for the majority of projects that have a similar setup, you will find that they recommend installing certain packages with their system package manager first, before building the Python source code.

This allows them to choose whatever package manager they have installed, and it should also be a quick and painless process.

Therefore, just change your installation instructions to the following:

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