Manually importing gtk fails: module not found
所以我想在命令行中反复执行一个python脚本,它必须非常快。python中的导入速度很慢,因为搜索整个
因此,我的想法是取代
1 2 | import sys import gdk.gtk |
具有
1 2 3 | import sys import imp imp.load_source("gtk.gdk","/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py") |
(我从
但是,python告诉我这是无效的:
(下面详细介绍错误消息)
1 2 3 4 5 6 7 8 9 | /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:23: RuntimeWarning: Parent module 'gtk' not found while handling absolute import import sys /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:30: RuntimeWarning: Parent module 'gtk' not found while handling absolute import import gobject as _gobject /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: RuntimeWarning: Parent module 'gtk' not found while handling absolute import from gtk import _gtk |
导入已编译的
1 2 3 | # done manually once file,filename,descr=imp.find_module('gtk') print file,filename,descr |
脚本:
1 2 3 4 | # script gtk=imp.load_module('gtk',FILE,FILENAME,DESCRIPTION) # the respective values # gtk=imp.load_module("gtk",None,"/usr/lib/python2.7/dist-packages/gtk-2.0/gtk",('','',5)) from gtk import gdk |