如何正确安装 PyGObject? (操作系统)

2023-12-03

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

因此,我们按照说明进行操作,但仍然处于开始状态,没有任何功能。

也尝试了各种--with-python3 and --without-python在brew安装过程中的选项。

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

有人可以告诉我我错过了什么吗?


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

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

显然,这不是最理想的,我们想要转移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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何正确安装 PyGObject? (操作系统) 的相关文章

随机推荐