你如何为python安装gtk(没有很多错误)

时间:2015-01-13 18:33:43

标签: python gtk pygtk macports

注意:这篇文章在底部的EDITs部分有几个发展。

我无法弄清楚为什么我的小程序会抛出错误。

似乎很多其他人都有同样的问题。我刚读了this article,基本上说安装gtk是不可能的。当然不是这样......

此外,这一个:import gtk not working on mac

让我们弄清楚这一点。

我认为控制台读数中最相关的一行(下面打印)是GtkWarning: Screen for GtkWindow not set; you must always set a screen for a GtkWindow before using the window。我已经用谷歌搜索了这个,但我无法弄清楚如何设置屏幕......"在使用窗口之前

which python/opt/local/bin/python,这就是我想要的,我想,因为我正在使用通过macports安装的库。

我已按照this帖子中提供的程序进行操作,因此我确信我正在运行py27-pygtk

#!/opt/local/bin/python2.7
import gtk, os

window = gtk.Window()
window.connect("destroy", gtk.main_quit)

image = gtk.Image()
window.add(image)
image.set_from_file(os.path.join("data", "image1.jpg"))

window.show_all()
gtk.main()

这是控制台读数:

$ python imageHello.py

** (process:691): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'

** (process:691): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'

** (process:691): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
imageHello.py:4: Warning: invalid (NULL) pointer instance
  window = gtk.Window()
imageHello.py:4: Warning: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
  window = gtk.Window()
imageHello.py:11: GtkWarning: Screen for GtkWindow not set; you must always set
a screen for a GtkWindow before using the window
  window.show_all()
imageHello.py:11: GtkWarning: gdk_screen_get_default_colormap: assertion 'GDK_IS_SCREEN (screen)' failed
  window.show_all()
imageHello.py:11: GtkWarning: gdk_colormap_get_visual: assertion 'GDK_IS_COLORMAP (colormap)' failed
  window.show_all()
imageHello.py:11: GtkWarning: gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed
  window.show_all()
imageHello.py:11: GtkWarning: gdk_window_new: assertion 'GDK_IS_WINDOW (parent)' failed
  window.show_all()
Segmentation fault: 11
编辑:我在某个地方读过(一旦发现它就会发布链接)你需要一些叫做x11的东西来使用gtk。所以我刚跑sudo port -v install xorg-server。这没有用。

EDIT2:刚刚下载了xquartz from their website。但是,我认为这是关键,我重启了我的电脑。现在我能够让我的程序正常运行。但是,我仍然收到以下警告。我不知道这意味着什么。有什么想法吗?

$ python imageHello.py

** (process:312): WARNING **: Trying to register gtype 'GMountMountFlags' as enum when in fact it is of type 'GFlags'

** (process:312): WARNING **: Trying to register gtype 'GDriveStartFlags' as enum when in fact it is of type 'GFlags'

** (process:312): WARNING **: Trying to register gtype 'GSocketMsgFlags' as enum when in fact it is of type 'GFlags'

0 个答案:

没有答案