如何正确安装PyGObject?(OSX) [英] How do I properly install PyGObject? (OSX)
问题描述
我想运行现有的简单示例,并使用GStreamer编写一些简单的代码-特别是使用其Python绑定.我想安装软件包等来启用它.
这是一个例子.
http://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.html
import gigi.require_version('Gst','1.0')从gi.repository导入GstGst.init(无)#...my_playbin = Gst.ElementFactory.make("playbin",无)断言my_playbin打印my_playbin
我无法使PyGObject正常工作,所以我被困在 import gi
上,并且无法在第一行之外取得任何进展.
平台是MacOS 10.12.6和Python 3.6.5.
computer:Desktop me $ python3Python 3.6.5(v3.6.5:f59c0932b4,2018年3月28日,05:52:31)达尔文上的[GCC 4.2.1兼容Apple LLVM 6.0(clang-600.0.57)]键入帮助",版权",信用"或许可证"以获取更多信息.>>>进口gi追溯(最近一次通话):在< module>中的文件< stdin>",第1行,ModuleNotFoundError:没有名为"gi"的模块>>>
好的,让我们RTFM.
https://pygobject.readthedocs.io/en/latest/getting_started.html#macosx-getting-started
似乎很简单,应该安装PyGObject,对吧?
我已经安装了Homebrew,但是请确保再次执行此操作.
计算机:台式机$/usr/bin/ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"==>该脚本将安装:/usr/local/bin/brew[为简洁起见]==>安装成功!==>下一步:-运行"brew help"以开始使用-更多文件:https://docs.brew.sh计算机:台式机
好的,现在我们安装pygobject3和gtk + 3
computer:Desktop me $ brew install pygobject3 gtk + 3正在更新自制软件...警告:pygobject3 3.32.1已经安装并且是最新的要重新安装3.32.1,运行`brew reinstall pygobject3`.警告:gtk + 3 3.24.8已经安装并且是最新的要重新安装3.24.8,请运行"brew reinstall gtk + 3".计算机:台式机
现在让我们再次尝试使用Python:
computer:Desktop me $ python3Python 3.6.5(v3.6.5:f59c0932b4,2018年3月28日,05:52:31)达尔文上的[GCC 4.2.1兼容Apple LLVM 6.0(clang-600.0.57)]键入帮助",版权",信用"或许可证"以获取更多信息.>>>进口gi追溯(最近一次通话):在< module>中的文件< stdin>",第1行,ModuleNotFoundError:没有名为"gi"的模块>>>
因此,我们已按照说明进行操作,现在仍然是我们没有任何功能的起点.
在brew安装过程中还尝试了各种-with-python3
和-without-python
选项.
computer:Desktop me $ brew install pygobject3 --with-python3 --without-python正在更新自制软件...[为方便起见]错误:无效选项:-with-python3
所有这些选项都是无效选项,尽管在各种Internet线程中都有提及.
computer:Desktop me $ brew install pygobject3 --with-python @ 2 gtk + 3正在更新自制软件...==>自动更新的自制软件!更新了1个水龙头(自制/酒桶).无需更改公式.[为方便起见]错误:无效选项:-with-python @ 2
有人可以告诉我我想念什么吗?
我知道这个答案有点晚了,但是我弄清楚了为什么它不起作用,以及将来遇到它的人的解决方法./p>
Homebrew将通过从软件包安装目录中进行符号链接来安装 pygobject3
,这意味着 pygobject3
仅可通过homebrew安装的python二进制文件进行访问.如果我在/usr/local/bin/python3
中使用python可执行文件,则 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:
<代码>(基本)2l4 @ mac105220:/usr/local/anaconda3/lib/python3.7/>PythonPython 3.7.3(默认,Mar 27 2019,16:54:48)[Clang 4.0.1(tags/RELEASE_401/final)] ::在达尔文的Anaconda,Inc.键入帮助",版权",信用"或许可证"以获取更多信息.>>>从gi.repository导入GLib>>>循环= GLib.MainLoop()>>>loop.run()
I want to run existing simple examples and write some simple code using GStreamer - specifically, using its Python bindings. I want to install the packages etc to enable that.
Here's an example.
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
I can't get PyGObject to work, so I'm stuck right at import gi
and can't make any progress beyond the first line.
The platform is MacOS 10.12.6, and 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'
>>>
Okay, let's RTFM.
https://pygobject.readthedocs.io/en/latest/getting_started.html#macosx-getting-started
Seems pretty simple and this should get PyGObject installed, right?
I've already got Homebrew installed, but let's just do it again to be sure.
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$
OK, now let's install pygobject3 and 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$
Now let's try Python again:
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'
>>>
So we've followed the instructions and we're still right where we started with no functionality.
Also tried various --with-python3
and --without-python
options during the brew install.
computer:Desktop me$ brew install pygobject3 --with-python3 --without-python
Updating Homebrew...
[SNIP FOR BREVITY]
Error: invalid option: --with-python3
All of these options are invalid options, despite being mentioned in various internet threads.
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
Can somebody tell me what I'm missing please?
I know this answer is a bit late, but I figured out why it isn't working and a workaround for those who run into it in the future.
Homebrew will install pygobject3
by symlinking it in from a package install directory, which means that pygobject3
is only accessible from the python binaries installed by homebrew. If I used the python executable at /usr/local/bin/python3
, the install location of brew install python
, pygobject3
imports just fine.
Obviously, that's suboptimal, and we want to transfer pygobject3
to our preferred installation of python.
I did it like so:
$ cd /usr/local/Cellar/pygobject3/3.34.0/lib/python3.7/site-packages/
$ sudo cp -rf * /usr/local/anaconda3/lib/python3.7/site-packages/
I can now import and use 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()
这篇关于如何正确安装PyGObject?(OSX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!