小能豆

如何在 macOS 上安装 gst-python 以与推荐的 GStreamer 安装程序配合使用?

py

我正在尝试使以下内容在 M1 Pro 上的 macOS 14.4.1 上运行:

$ python3
Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import gi
>>> gi.require_version('GLib', '2.0')
>>> gi.require_version('GObject', '2.0')
>>> gi.require_version('Gst', '1.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.12/site-packages/gi/__init__.py", line 126, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace Gst not available

笔记:

$ which python3
/opt/homebrew/bin/python3

我发现了这个问题:在 macOS 中安装 gst-python。看来我需要安装 gst-python。我已经安装了GStreamer的 1.24 运行时和开发安装程序——在阅读那里的说明后,我选择不使用 Homebrew——但显然 gst-python 没有随它一起安装。

描述了克隆gstreamer GitLab 存储库然后构建gst-python 子项目,因此我尝试了相同的操作:

$ meson setup builddir -Dpygi-overrides-dir=/opt/homebrew/lib/python3.12/site-packages/gi/overrides && ninja -C builddir
The Meson build system
Version: 1.4.0
Source dir: /Users/dspitzer/dev/from_gitlab/gstreamer/subprojects/gst-python
Build dir: /Users/dspitzer/dev/from_gitlab/gstreamer/subprojects/gst-python/builddir
Build type: native build
Project name: gst-python
Project version: 1.24.1.1
C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
C linker for the host machine: cc ld64 1053.12
Host machine cpu family: aarch64
Host machine cpu: aarch64
Found pkg-config: YES (/Library/Frameworks/GStreamer.framework/Versions/1.0/bin/pkg-config) 0.29.2
Run-time dependency gstreamer-1.0 found: YES 1.24.1
Run-time dependency gstreamer-base-1.0 found: YES 1.24.1
Run-time dependency gmodule-no-export-2.0 found: YES 2.74.4
Library dl found: YES
Found CMake: /opt/homebrew/bin/cmake (3.29.1)
Run-time dependency pygobject-3.0 found: NO (tried pkgconfig, framework and cmake)
Looking for a fallback subproject for the dependency pygobject-3.0

meson.build:26:16: ERROR: Neither a subproject directory nor a pygobject.wrap file was found.

A full log can be found at /Users/dspitzer/dev/from_gitlab/gstreamer/subprojects/gst-python/builddir/meson-logs/meson-log.txt

但我不知道如何修复“发现运行时依赖项 pygobject-3.0:否”。

注意: 评论指出pip3下面的命令使用的是不同版本的 Python。我已修复此问题 - 因此您可以跳至下面的“更新”。

我找到了并成功运行,brew install pygobject3 gtk+3但是:

$ pip3 install pygobject
Collecting pygobject
  Using cached pygobject-3.48.1.tar.gz (714 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      + meson setup /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129 /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129/.mesonpy-aial33lr -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Dtests=false -Dwheel=true --wrap-mode=nofallback --native-file=/private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129/.mesonpy-aial33lr/meson-python-native-file.ini
      The Meson build system
      Version: 1.4.0
      Source dir: /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129
      Build dir: /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129/.mesonpy-aial33lr
      Build type: native build
      Project name: pygobject
      Project version: 3.48.1
      C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
      C linker for the host machine: cc ld64 1053.12
      Host machine cpu family: aarch64
      Host machine cpu: aarch64
      Program python3 found: YES (/Users/dspitzer/.new_local/share/pyenv/versions/3.11.7/bin/python3.11)
      Found pkg-config: YES (/Library/Frameworks/GStreamer.framework/Commands/pkg-config) 0.29.2
      Run-time dependency python found: YES 3.11
      Found CMake: /opt/homebrew/bin/cmake (3.29.1)
      Run-time dependency gobject-introspection-1.0 found: NO (tried pkgconfig, framework and cmake)
      Not looking for a fallback subproject for the dependency gobject-introspection-1.0 because:
      Use of fallback dependencies is disabled.

      ../meson.build:29:9: ERROR: Dependency 'gobject-introspection-1.0' is required but not found.

      A full log can be found at /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-thqb1k2v/pygobject_ad81b1b46af0427a953b312d45c6e129/.mesonpy-aial33lr/meson-logs/meson-log.txt
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

更新:我已将$HOME/.new_local/bin(由 GStreamer 安装创建的)添加到我的 PATH 中,因此/opt/homebrew/bin运行pip3前者中的那个,从而产生了不同版本的 Python。

所以我修复了路径并重新运行:

$ pip3 install pygobject
Collecting pygobject
  Downloading pygobject-3.48.2.tar.gz (715 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 715.2/715.2 kB 13.3 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      + meson setup /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d/.mesonpy-rhycpxqs -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md -Dtests=false -Dwheel=true --wrap-mode=nofallback --native-file=/private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d/.mesonpy-rhycpxqs/meson-python-native-file.ini
      The Meson build system
      Version: 1.4.0
      Source dir: /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d
      Build dir: /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d/.mesonpy-rhycpxqs
      Build type: native build
      Project name: pygobject
      Project version: 3.48.2
      C compiler for the host machine: cc (clang 15.0.0 "Apple clang version 15.0.0 (clang-1500.3.9.4)")
      C linker for the host machine: cc ld64 1053.12
      Host machine cpu family: aarch64
      Host machine cpu: aarch64
      Program python3 found: YES (/Users/dspitzer/dev/python/dashboard-fake-frontend/env/bin/python3.12)
      Found pkg-config: YES (/Library/Frameworks/GStreamer.framework/Versions/1.0/bin/pkg-config) 0.29.2
      Run-time dependency python found: YES 3.12
      Found CMake: /opt/homebrew/bin/cmake (3.29.1)
      Run-time dependency gobject-introspection-1.0 found: NO (tried pkgconfig, framework and cmake)
      Not looking for a fallback subproject for the dependency gobject-introspection-1.0 because:
      Use of fallback dependencies is disabled.

      ../meson.build:29:9: ERROR: Dependency 'gobject-introspection-1.0' is required but not found.

      A full log can be found at /private/var/folders/sb/329vdstd77q73c_7j_smp9r40000gp/T/pip-install-i7tjs1ue/pygobject_d272551047184d069c19b9453f89f97d/.mesonpy-rhycpxqs/meson-logs/meson-log.txt
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

因此 Python 版本不是问题。

现在我被困在这儿了。


阅读 19

收藏
2024-12-09

共1个答案

小能豆

你遇到的错误提示显示 gobject-introspection-1.0 这个依赖没有被找到,这通常意味着缺少一些必要的开发库。这是 pygobjectgst-python 构建时的常见问题。你需要确保以下几个关键的依赖项已经安装和正确配置。

解决方案步骤:

  1. 安装 gobject-introspection
    gobject-introspection 是构建 pygobject 所必需的。如果你没有安装它,安装它应该能解决这个问题。

在 macOS 上,你可以通过 brew 安装 gobject-introspection
bash brew install gobject-introspection

这将确保你安装了必要的开发库,并且配置了 pkg-config 来找到它们。

  1. 安装 pygobject
    在确保 gobject-introspection 安装完毕后,再次尝试安装 pygobject
    bash pip3 install pygobject

  2. 确保 GStreamer 环境变量正确配置
    你已经安装了 GStreamer,但需要确保 GStreamer 的路径已被正确设置。你可以将 pkg-configGStreamer 的路径添加到环境变量中,确保构建时能找到它们。

修改 ~/.bash_profile~/.zshrc 文件(取决于你使用的 shell)并添加以下内容:
bash export PKG_CONFIG_PATH=/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/pkgconfig:$PKG_CONFIG_PATH export GST_PLUGIN_PATH=/Library/Frameworks/GStreamer.framework/Versions/1.0/lib/gstreamer-1.0

然后运行:
bash source ~/.zshrc # 如果你使用的是 zsh source ~/.bash_profile # 如果你使用的是 bash

  1. 重新构建和安装 gst-python
    现在你应该能够使用 pip 安装 pygobjectgst-python。首先尝试安装 gst-python,如果你仍然需要手动构建,可以按照以下步骤:
    bash pip3 install gst-python

如果此操作仍然失败,尝试从源代码构建 gst-python,这时需要确保已安装所有开发工具(如 clang, make, pkg-config)以及 GStreamer 开发包。

额外调试建议:

  • 检查 pkg-config 是否能找到依赖项
    确保 pkg-config 能正确地找到 gobject-introspectiongstreamer。运行以下命令检查:
    bash pkg-config --cflags --libs gstreamer-1.0 pkg-config --cflags --libs gobject-introspection-1.0

如果这两个命令返回了正确的输出(即路径),说明它们配置正确。

  • 手动设置路径
    如果 pkg-config 无法找到 gobject-introspection,你可以尝试手动设置 PKG_CONFIG_PATH 指向正确的路径。例如,运行:
    bash export PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH

总结:

  1. 确保 gobject-introspection 已安装并通过 brew 配置。
  2. 确保 pkg-config 能找到所有必要的依赖项。
  3. 如果问题仍然存在,手动检查和设置环境变量路径。

如果按照这些步骤仍然有问题,请提供更多的错误信息,我们可以继续排查。

2024-12-09