PyGObject for Python 3.5.1?

匿名 (未验证) 提交于 2019-12-03 09:06:55

问题:

I am using Debian Linux, and I have the package python3-gi installed from Synaptic, and this works fine if I use my Python 3.4 interpreter. But, when I run a Gtk+3 program using 3.5, it gets stuck at the from gi.repository import Gtk line, saying there's no module named Gtk. Additionally, I don't think that pip works for Python 3.5 on my computer, although I'm not sure. I just know that pip install PyGObject doesn't work. Finally, when I try to use Pycharm's specific package installer (Settings/Project Interpreter), Pycharm tells me that I don't have Python packaging tools installed (and it fails to install them when I click on the prompt it gives).

I have a 64 bit computer, Python 3.5 is installed to /usr/local/bin/ and Python 3.4 is installed to /usr/bin/.

回答1:

You cannot use pip, you would have to download pygobject and build it from source yourself. https://download.gnome.org/sources/pygobject/



回答2:

This is how I got Python 3.6 up and running with GStreamer bindings etc. on my Mac OS Sierra.

Follow from Step 1 if you have already installed Gstreamer and its plugins and you need to bind it to your python interpreter for development.

0a- Install gstreamer from their website ...normally and then

0b- brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav

1- brew install gst-python --with-python3

Note however that the 'gtk' for some reason doesn't come pre-bundled so we go to step 2.

2- brew install gtk+3

And that's it, easy as ABC...

Attached is a test python code to make sure you got everything right [OPTIONAL]

import gi, time, sys gi.require_version('Gst', '1.0') gi.require_version('GstBase', '1.0') gi.require_version('Gtk', '3.0') from gi.repository import GObject, Gst, GstBase, Gtk, GObject  class Main:    def __init__(self):        Gst.init(None)        self.pipeline = Gst.Pipeline()        self.audiotestsrc = Gst.ElementFactory.make('audiotestsrc',  'audio')        self.pipeline.add(self.audiotestsrc)         self.sink = Gst.ElementFactory.make('autoaudiosink', 'sink')        self.pipeline.add(self.sink)        self.audiotestsrc.link(self.sink)        self.pipeline.set_state(Gst.State.PLAYING)        time.sleep(3)        self.pipeline.set_state(Gst.State.PAUSED)        self.pipeline.set_state(Gst.State.READY)        self.pipeline.set_state(Gst.State.NULL)        sys.exit(0) start =  Main() Gtk.main() 

Hope er'thing works out, c ya!!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!