我想运行现有的简单示例,并使用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


尽管在各种Internet线程中都有提及,但所有这些选项都是无效选项。

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


有人可以告诉我我想念的东西吗?

最佳答案

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

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()

关于python - 如何正确安装PyGObject? (OSX),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56629270/

10-11 23:23
查看更多