简体   繁体   中英

psutil module not fully working on debian 7

I'm trying to get the amount of free memory in the system using python. basically the same info that i can get from cat /proc/meminfo | grep MemFree 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'

i'm using python 2.7.3

update

>>> psutil.__version__
'0.5.0'
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

Possibly you need to run:

sudo pip install psutil --upgrade

Note that you will never get exactly the same answers as you are running python in one case and not in the other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM