适用于Python 3.5.1的PyGObject? [英] PyGObject for Python 3.5.1?

查看:134
本文介绍了适用于Python 3.5.1的PyGObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Debian Linux,并且已经从Synaptic安装了软件包python3-gi,如果我使用Python 3.4解释器,则可以正常工作.但是,当我使用3.5运行Gtk + 3程序时,它陷入了from gi.repository import Gtk行,并说没有名为Gtk的模块.另外,尽管不确定,我不认为该pip适用于我的计算机上的Python 3.5.我只知道pip install PyGObject不起作用.最后,当我尝试使用Pycharm的特定程序包安装程序(Settings/Project Interpreter)时,Pycharm告诉我我没有安装Python打包工具(当我单击它给出的提示时,它无法安装).

我有一台64位计算机,在/usr/local/bin/中安装了Python 3.5,在/usr/bin/中安装了Python 3.4.

解决方案

这是我启动Python 3.6并在Mac OS Sierra上使用GStreamer绑定等运行的方式.

遵循步骤1 ,如果您已经安装了Gstreamer及其插件,则需要将其绑定到python解释器进行开发.

0a-从其网站上正常安装gstreamer,然后

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

但是请注意,由于某种原因'gtk'并未预先打包,因此我们转到步骤2.

2- brew install gtk + 3

就是这样,就像 ABC ...

随附了一个测试python代码,以确保您一切正常[可选]

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

希望一切正常,是的!

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/.

解决方案

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!!

这篇关于适用于Python 3.5.1的PyGObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆