Get total physical memory in Python

后端 未结 4 1467
野的像风
野的像风 2020-12-02 07:24

How can I get the total physical memory within Python in a distribution agnostic fashion? I don\'t need used memory, just the total physical memory.

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 08:25

    your best bet for a cross-platform solution is to use the psutil package (available on PyPI).

    from psutil import virtual_memory
    
    mem = virtual_memory()
    mem.total  # total physical memory available
    

    Documentation for virtual_memory is here.

提交回复
热议问题