如何使用python-apt获取软件包描述?

我正在尝试创建一个图形化程序,以便为最终用户轻松处理软件包。然而,我在获取软件包描述以及其他一些信息方面遇到了问题。
我在这里看到了python-apt API,并且我理解我需要处理apt.package.Version() class
但是当我尝试使用它时,我只得到了一些错误,例如:
Traceback (most recent call last):
File "./myprogram", line 6, in <module>
print package.description
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 374, in description
dsc = self._translated_records.long_desc
File "/usr/lib/python2.7/dist-packages/apt/package.py", line 315, in _translated_records
desc_iter = self._cand.translated_description
AttributeError: 'list' object has no attribute 'translated_description'

有没有人可以为apt.package.Version()类创建一个运行示例呢?
谢谢!

请验证您是否有长描述(对某个软件包执行apt-cache show命令)。文档中提到了长描述,所以http://askubuntu.com/a/558389/158442可能会有帮助。 - muru
1个回答

以下的Python命令在长描述可用时应该返回给您:
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt
>>> cache = apt.Cache()
>>> pkg = cache['python2.7']
>>> pkg
<Package: name:'python2.7' architecture='amd64' id:1247L>
>>> pkg.versions
<VersionList: ['2.7.6-8']>
>>> pkg.versions[0]
<Version: package:'python2.7' version:'2.7.6-8'>
>>> pkg.versions[0].description
u'Python is a high-level, interactive, object-oriented language. Its 2.7 version
includes an extensive class library with lots of goodies for network programming, 
system administration, sounds and graphics.'
>>> 

注意:我的区域设置为LANG=en_US.UTF-8,所以翻译的字符串可能不是问题。