问题描述
我现在有一个项目,我正在使用 WNCK 来查找打开窗口的位置,并将它们聚焦.我最近添加了需要 Python 3.5 的功能,但 WNCK 仅适用于 Python 2.7 或我安装的任何内容.运行 python3 stuff.py 时,我得到了
导入错误:没有名为wnck"的模块
有谁知道我如何获得 Python 3 的 wnck 库?我以前用 sudo apt-get install python-wnck 为 python2 得到它
我使用的是 Ubuntu,所以如果答案是无法让 WNCK 工作,请切换到 X",请确保它不是仅适用于 Windows 的解决方案
从 python3 开始,wnck 是 GObject Introspection API.您现在可以在 Debian 上的 python3 中访问 wnck3(因此我认为在 Ubuntu 上也是如此):
apt-get install python3-gi gir1.2-wnck-3.0
显然,gir- 和 wnck- 版本会随时间变化(或者您可能需要例如较旧版本的 wnck),但是:
apt-cache search 'gir.*wnck'
应该足以找到你想要的东西.我个人更喜欢利用 aptitude-search 的力量
aptitude search '?depends(libgirepository) wnck'
由于 Introspection API 的灵活性,导入稍微更复杂,例如:
>>>进口GI>>>gi.require_version('Wnck', '3.0')>>>从 gi.repository 导入 Wnck可以在此处找到有关 python3/wnck3 的文档.
I have a project right now and I'm using WNCK to find the location of open windows, as well as focus them. I recently added features that require Python 3.5, but WNCK is only working with Python 2.7 or whatever I have installed. When running python3 stuff.py, I'm getting
ImportError: No module named 'wnck'
Does anyone know how I can get the wnck library for Python 3? I previously got it for python2 with sudo apt-get install python-wnck
I'm using Ubuntu, so if the answer is anything like "Can't get WNCK working, switch to X", please make sure it's not a windows only solution
From python3 onwards wnck is part of the GObject Introspection API. You can presently get access to wnck3 in python3 on Debian (and therefore I presume identically on Ubuntu) with:
apt-get install python3-gi gir1.2-wnck-3.0
Obviously the gir- and wnck- versions will vary over time (or you may need e.g. an older version of wnck), but:
apt-cache search 'gir.*wnck'
should be enough for finding what you want. I personally prefer to leverage the power of aptitude-search with
aptitude search '?depends(libgirepository) wnck'
Due to the flexibility of the Introspection API, importing is slightly more complex, for example:
>>> import gi
>>> gi.require_version('Wnck', '3.0')
>>> from gi.repository import Wnck
Documentation for python3/wnck3 can be found here.
这篇关于让 WNCK 使用 Python 3.5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!