What are the steps to correctly set up PyGObject on macOS?

I am looking to run some basic examples and write code using GStreamer with its Python bindings. I need help installing the necessary packages to get started.

Check out this example:

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 am currently having trouble getting PyGObject to work, as I cannot progress beyond the first line import gi.

I am using 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'
>>> 

Let's consult the official documentation.

This should guide us through installing PyGObject correctly, right?

I already have Homebrew installed, but I will reinstall it just to be safe.

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$ 

Now, let's proceed with installing 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$

Let's test 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'
>>> 

Despite following the instructions, we still face the initial issue with no solution in sight.

We also tried different options such as --with-python3 and --without-python during the brew installation process.

computer:Desktop me$ brew install pygobject3 --with-python3 --without-python
    Updating Homebrew...

    [SNIP FOR BREVITY]

    Error: invalid option: --with-python3

All these options turned out to be invalid despite suggestions from online forums.

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

If anyone could provide insight into what might be missing, I would greatly appreciate it.

Answer №1

Apologies for the delay in providing this solution, but I have identified why the original method was not effective and have come up with a workaround for anyone encountering this issue in the future.

When using Homebrew to install pygobject3, it creates a symbolic link from a package installation directory, restricting access to pygobject3 solely from python binaries installed by Homebrew. However, by utilizing the python executable located at /usr/local/bin/python3, which corresponds to the install location of brew install python, you can successfully import pygobject3.

While this method works, it is not ideal and we may prefer to transfer pygobject3 to our preferred python installation.

I accomplished this task as follows:

$ cd /usr/local/Cellar/pygobject3/3.34.0/lib/python3.7/site-packages/
$ sudo cp -rf * /usr/local/anaconda3/lib/python3.7/site-packages/

Following this process, I am now able to import and utilize 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()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Gather identification (ID) and row count from SQL query and store in the column labeled value

I am working with a dataframe that has the following structure: ID SQL 0 ID_24 Select * from table1 1 ID_42 Select * from table2 My goal is to create a for loop that loops through these rows and adds the number of ...

Selenium is unable to locate an element using Jquery

sel.add_script( sel.get_location(), "jquery.js") #I am getting u'fd6c42bcc770ca9decc4f358df3688290a4257ad' idOfResultWithSomeImage=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=SeleImage]') ...

Problem - b'Issue with starting sasl_client (-4) SASL(-4): no mechanism available: Callback not found: 2'

I am attempting to establish a connection to HIVE using Python in Jupyter Notebooks. I have successfully installed all the required packages for connecting to HIVE using Python: sasl 0.2.1 py37h8a4fda4_1 thrift ...

Determining the quantity of associated objects in Django

Is there a more efficient way to count related objects in Django without running numerous queries? Let's illustrate with tables A and B, where each B is linked to one A. The approach attempted was: A.objects.select_related().filter(attr=val) A[i].B_ ...

Looking to access nasdaq.com using both Python and Node.js

Having an issue with a get request for nasdaq.com. Attempting to scrape data with nodejs, but only receiving 'ECONNRESET' after trying multiple configurations. Python, on the other hand, works flawlessly. Currently using a workaround by fetching ...

Come together with the arrow structs to perform a joint operation on attributes

If we consider a hypothetical json file labeled 'my_data.json' with the following content. {"a": [1, 2], "b": {"c": true, "d": "1991-02-03"}} {"a": [3, 4, 5], "b": {"c": false, "d": "2019-04-01"}} In scenarios where a join operation based on at ...

Utilizing WebIOPi in Your Current Website

I'm currently navigating the complexities of WebIOPi and struggling to integrate it into my project. Here's some background information: I am utilizing a Raspberry Pi B+ with Wheezy installed. My focus is on developing a web-based application th ...

Are Json.load operations considered inefficient?

While browsing through the json module's source code in search of an answer to another question, I stumbled upon something quite intriguing. After removing the docstring and various keyword arguments, the essence of json.load is revealed as follows: ...

Encountered a ValueError while attempting to convert data types from float to string within a column

I'm struggling to rename certain values within a column in this specific manner: values less than or equal to 150; values between 150 and 300 (inclusive); values greater than 300. The column originates from a dataframe: Value 0 146.0 2 148.0 ...

Save the result to either one of two files based on the evaluation of an if statement

I've been utilizing the python nmap module for certificate discovery and monitoring. import nmap import time import datetime from contextlib import redirect_stdout from datetime import date import itertools Here's the function responsible for m ...

Ways to enhance functionality with fsolveıcı

For each iteration, I need to use the fsolve. Suppose I have a DataFrame like this: PD Downturn PD TTC 0.12 0.008 0.15 0.016 0.24 0.056 0.56 0.160 1.00 1.000 This is the code snippet I am using: result = [] for i in range(len(df) - 1): d ...

Authorization error preventing nose test coverage

I just started using nosetests today and everything was going smoothly until I attempted the following command: nosetests --with-coverage --cover-html --cover-html-dir=/tmp/cache. Suddenly, a permission denied error popped up, leaving me puzzled as to why ...

Exploring Selenium With Various Network Connections

I have a Linux system with two different interfaces (such as eth0 and tap0). I'm trying to run two separate instances of selenium phantomjs browsers simultaneously, each using a different interface. Is it possible to choose which interface to use in s ...

A Python list containing a variable as a reference

I have labeled my lists as layer1, layer2 ... sequentially. I am looking to utilize a variable called playerY to reference the specific numbered list when calling it. For example, if the value of playerY is 4, then I want to access the content of layer4. ...

Converting Nested JSON into a Pandas Data Frame

How can we efficiently convert the following JSON dataset snapshot into a Pandas Data Frame? Importing the file directly results in a format that is not easily manageable. Presently, I am utilizing json_normalize to separate location and sensor into diff ...

Guide on utilizing a single JSON label file for all YOLO-NAS training images

Looking to implement the YOLO object detection Model? I have successfully annotated my images and have them in coco format. I now have a Json file containing label annotations for the train, test, and valid data sets. When defining the model's confi ...

Using Scrapy and Selenium to scrape a website that needs authentication

I've encountered a challenge while attempting to extract data from a webpage that heavily relies on AJAX calls and javascript for its rendering. My approach involves using scrapy in combination with selenium to achieve this task. Here's the metho ...

Is it possible to evaluate the visual responses when interacting with an element?

Is it feasible to assess the visual response of an element during interaction? For instance, imagine there is a button on the webpage that visually becomes active a few moments after being clicked. Similar to the quick animation shown after clicking one o ...

Transforming a Microsoft SQL Server varbinary into a base64 encoded string

The objective I need to retrieve an image from a mssql database, convert it to base64 format, and then embed it in an email. Specifics The image is stored as varbinary data in the mssql database. 0xFFD8FFE00.... Upon querying this image in an outdated J ...

What is the best way to format a list for writing into a file?

I am working with a Python list and I want to format it in a specific way. Input: trend_end= ['skill1',10,0,13,'skill2',6,1,0,'skill3',5,8,9,'skill4',9,0,1] I need the file to look like this: Output: 1 2 3 1 ...