python - psutil 模块在 debian 7 上无法完全工作

标签 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'

最佳答案

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 - psutil 模块在 debian 7 上无法完全工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20027440/

相关文章:

python - Scipy 中具有两个变量的函数中一个变量的定积分

swift - 我的变量存储在哪里? ( swift )

c - 将内存分配给c中的字符串数组

python - Scrapy 在 "__init__"之后不调用任何其他函数

python - 使用 Pattern.sub(r'\1' 时出现错误 "sre_constants.error: unmatched group"

python - 无法导入模块

python - 多个 if 和 else 语句

python - 问题: Correlation always gives nan values

python - 回溯(最近一次调用): IOError: [Errno 13] Permission denied: 'demo.docx'

c - X 处的堆 block 在 Y 处修改为过去请求的大小 - 释放分配的内存