Home > Mobile >  How to get available memory (ram) in python?
How to get available memory (ram) in python?

Time:09-27

I couldn't find an answer in the internet or stackoverflow but I have tried this method but it's not good one

from os import popen
output  = popen("free -ht").read()
print(output[154:-90])
output: 2.4G

Is there any python library for this or at least a solution.

CodePudding user response:

You can get the RAM count using psutil

>>> import psutil
>>> psutil.virtual_memory()
svmem(total=16717422592, available=5376126976, percent=67.8, used=10359984128, free=1831890944, active=7191916544, inactive=2325667840, buffers=525037568, cached=4000509952, shared=626225152)
  • Related