Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

linux - Get total physical memory in Python

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.

question from:https://stackoverflow.com/questions/65939913/how-to-detect-how-much-memory-a-computer-has-installed-in-it-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...