无法使用psutil获取进程名称

时间:2015-05-16 21:04:57

标签: python psutil

我正在使用它来获取当前进程。它可以在我的机器上运行,但是当我在另一台机器上运行它时它不会运行。

for p in psutil.process_iter():
    try:
        proc_names[p.pid] = p.name()
    except psutil.Error:
        pass
for c in psutil.net_connections(kind='inet'):
# etc...

我收到此错误

    proc_names[p.pid] = p.name()
TypeError: 'str' object is not callable

使用p.name,而不是我得到这个

    for c in psutil.net_connections(kind='inet'):
AttributeError: 'module' object has no attribute 'net_connections'

1 个答案:

答案 0 :(得分:0)

我猜你的机器正在使用更新版本的psutil(2.x)而另一台机器正在使用1.x版本。

将p.name()更改为p.name是正确的举措,但我认为1.x中不存在net_connections。请尝试get_connections或在其他计算机上更新psutil

相关问题