【问题标题】:How do I properly install PyGObject? (OSX)如何正确安装 PyGObject? (OSX)
【发布时间】:2019-06-17 10:18:32
【问题描述】:

我想运行现有的简单示例并使用 GStreamer 编写一些简单的代码 - 特别是使用它的 Python 绑定。我想安装软件包等来启用它。

这是一个例子。

http://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.html

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
Gst.init(None)
# ...
my_playbin = Gst.ElementFactory.make("playbin", None)
assert my_playbin
print my_playbin

我无法让 PyGObject 工作,所以我被困在import gi 并且无法在第一行之外取得任何进展。

平台为 MacOS 10.12.6 和 Python 3.6.5。

computer:Desktop me$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>> 

好的,让我们进行 RTFM。

https://pygobject.readthedocs.io/en/latest/getting_started.html#macosx-getting-started

看起来很简单,这应该安装 PyGObject,对吧?

我已经安装了 Homebrew,但让我们再做一次以确保。

computer:Desktop me$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

==> This script will install:
/usr/local/bin/brew

[Snip for brevity]

==> Installation successful!

==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

computer:Desktop me$ 

好的,现在让我们安装 pygobject3 和 gtk+3

computer:Desktop me$ brew install pygobject3 gtk+3
Updating Homebrew...
Warning: pygobject3 3.32.1 is already installed and up-to-date
To reinstall 3.32.1, run `brew reinstall pygobject3`
Warning: gtk+3 3.24.8 is already installed and up-to-date
To reinstall 3.24.8, run `brew reinstall gtk+3`
computer:Desktop me$

现在让我们再次尝试 Python:

computer:Desktop me$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>> 

所以我们已经按照说明进行操作,但我们仍然在我们开始的地方没有任何功能。

还在 brew 安装期间尝试了各种 --with-python3--without-python 选项。

computer:Desktop me$ brew install pygobject3 --with-python3 --without-python
    Updating Homebrew...

    [SNIP FOR BREVITY]

    Error: invalid option: --with-python3

所有这些选项都是无效选项,尽管在各种互联网线程中都提到过。

computer:Desktop me$ brew install pygobject3 --with-python@2 gtk+3
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.

[SNIP FOR BREVITY] 

Error: invalid option: --with-python@2

谁能告诉我我错过了什么?

【问题讨论】:

  • 我不熟悉 GStreamer,但是当我意识到官方说明只考虑您使用安装了自制的 python 解释器的情况时,我刚刚用 Gtk/PyGObject 解决了这个问题。这可能会有所帮助stackoverflow.com/a/60701630/5824843

标签: python gstreamer pygobject


【解决方案1】:

我知道这个答案有点晚了,但我弄清楚了为什么它不起作用,并为将来遇到它的人提供了一个解决方法。

Homebrew 将通过符号链接从软件包安装目录中安装pygobject3,这意味着pygobject3 只能从 Homebrew 安装的 python 二进制文件中访问。如果我在/usr/local/bin/python3使用python可执行文件,brew install pythonpygobject3的安装位置导入就好了。

显然,这是次优的,我们希望将 pygobject3 转移到我们首选的 python 安装中。

我是这样做的:

$ cd /usr/local/Cellar/pygobject3/3.34.0/lib/python3.7/site-packages/
$ sudo cp -rf * /usr/local/anaconda3/lib/python3.7/site-packages/

我现在可以导入和使用 gi:

(base) 2l4@mac105220:/usr/local/anaconda3/lib/python3.7/ > python
Python 3.7.3 (default, Mar 27 2019, 16:54:48)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import GLib
>>> loop = GLib.MainLoop()
>>> loop.run()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-07
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    相关资源
    最近更新 更多