Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

module - Get WNCK working with Python 3.5?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...