psutil模块没有完全在debian 7上运行

时间:2013-11-17 05:08:38

标签: python memory python-2.7 system

我正在尝试使用python获取系统中的可用内存量。基本上我可以从cat /proc/meminfo | grep MemFree获得相同的信息。

>>> import psutil
>>> psutil.NUM_CPUS # this works fine
2
>>> psutil.virtual_memory() # this fails
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'virtual_memory'

我正在使用python 2.7.3

更新

>>> psutil.__version__
'0.5.0'

1 个答案:

答案 0 :(得分:2)

Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.NUM_CPUS # this works fine
4
>>> psutil.virtual_memory() # this fails
vmem(total=4042084352L, available=1697619968L, percent=58.0, used=3149373440L, free=892710912L, active=2016649216, inactive=835248128, buffers=55672832L, cached=749236224)
>>> quit()
~$ cat /proc/meminfo | grep MemFree
MemFree:          876836 kB
~$ python -c "print 892710912/1024"
871788
~$ python -c "import psutil;print psutil.__version__"
1.1.3

可能你需要跑:

sudo pip install psutil --upgrade

请注意,在一个案例中运行python而在另一个案例中运行python时,你永远不会得到完全相同的答案。