4

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?

1
  • I'm not familiar with GStreamer but I just went through this problem with Gtk/PyGObject when i realised that the official instructions only consider the case of you using the homebrew installed python intepreter. This might be of help stackoverflow.com/a/60701630/5824843
    – Hansang
    Mar 16, 2020 at 7:12

1 Answer 1

4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.