首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何正确安装PyGObject?(OSX)

如何正确安装PyGObject?(OSX)
EN

Stack Overflow用户
提问于 2019-06-17 18:18:32
回答 1查看 3.3K关注 0票数 3

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

下面是一个例子。

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

代码语言:javascript
复制
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和Python3.6.5。

代码语言:javascript
复制
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,但为了确保这一点,让我们再来一次。

代码语言:javascript
复制
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

代码语言:javascript
复制
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:

代码语言:javascript
复制
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选项。

代码语言:javascript
复制
computer:Desktop me$ brew install pygobject3 --with-python3 --without-python
    Updating Homebrew...

    [SNIP FOR BREVITY]

    Error: invalid option: --with-python3

所有这些选项都是无效的选项,尽管在各种互联网帖子中都有提到。

代码语言:javascript
复制
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

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

EN

回答 1

Stack Overflow用户

发布于 2019-10-09 03:36:53

我知道这个答案有点晚了,但我明白了为什么它不起作用,并为将来遇到它的人提供了一种变通方法。

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

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

我是这样做的:

代码语言:javascript
复制
$ 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:

代码语言:javascript
复制
(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()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56629270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档