最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Python中查看当前系统的硬件配置和系统平台和版本等系统信息

Python crifan 506浏览 0评论
折腾:
【未解决】Mac中如何从命令行终端中启动wine
期间,想要去Python中,查看当前系统的信息,比如基本硬件和cpu等,软件的系统平台,版本等相关信息。
之前记得有个sys,但是只记得一个sys.platform,比较简单。
想要查看更多的详细的系统信息。
How to get the system info with Python? – Stack Overflow
 ✘ ⚙ xxx@xx  ~  wine python
0009:fixme:msvcrt:_configure_wide_argv (1) stub
0009:fixme:msvcrt:_initialize_wide_environment stub
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.platform
'win32'
>>> platform.machine()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'platform' is not defined
>>> import platform
>>> platform.machine()
'AMD64'
>>> platform.version()
'5.1.2600'
>>> platform.platform()
'Windows-XP-5.1.2600'
>>> platform.uname()
uname_result(system='Windows', node=‘xxx021', release='XP', version='5.1.2600', machine='AMD64', processor='AMD64 Family 6 Model 142 Stepping 10, GenuineIntel')
>>> platform.system()
'Windows'
>>> platform.processor()
'AMD64 Family 6 Model 142 Stepping 10, GenuineIntel'
>>> import os
>>> os.uname()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'os' has no attribute 'uname'
>>>
python – Getting computer hardware information – Stack Overflow
Getting Computer System Information using Python – Stack Overflow
>>> import socket
>>> socket.gethostname()
‘xxx021'
>>> socket.getfqdn()
0009:err:winediag:WS_getaddrinfo Failed to resolve your host name IP
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>>> platform.release()
'XP'
How to Get Hardware and System Information in Python – Python Code
此处不想安装第三方库:psutil
>>> import uuid
>>> uuid.getnode()
0
python – Get system information(CPU speed-Total RAM-Graphic Card model etc.) under Windows – Stack Overflow
How can I read system information in Python on Windows? – Stack Overflow
【总结】
此处如果只是查看当前系统的基本的概要的软硬件的信息的话,则可以:
import platform
platform.uname()
即可。
比如:
Mac
 python
Python 3.8.0 (default, Jan  6 2020, 10:33:50)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.uname()
uname_result(system='Darwin', node=‘xxx021', release='18.7.0', version='Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64', machine='x86_64', processor='i386')
Mac中Wine == Windows XP:
 wine python
002a:fixme:msvcrt:_configure_wide_argv (1) stub
002a:fixme:msvcrt:_initialize_wide_environment stub
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.uname()
uname_result(system='Windows', node=‘xxx021', release='XP', version='5.1.2600', machine='AMD64', processor='AMD64 Family 6 Model 142 Stepping 10, GenuineIntel')
如果想要查看详细的各项信息,则是:
代码:
import platform
platform.uname()
platform.machine()
platform.platform()
platform.system()
platform.release()
platform.version()
platform.processor()
import sys
sys.platform

import socket
socket.gethostname()
socket.getfqdn()
Mac输出效果:
 ✘ ⚙ xxx@xxx  ~  python
Python 3.8.0 (default, Jan  6 2020, 10:33:50)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.uname()
uname_result(system='Darwin', node=‘xxx021', release='18.7.0', version='Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64', machine='x86_64', processor='i386')
>>> platform.uname()
uname_result(system='Darwin', node=‘xxx021', release='18.7.0', version='Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64', machine='x86_64', processor='i386')
>>> platform.platform()
'macOS-10.14.6-x86_64-i386-64bit'
>>> platform.system()
'Darwin'
>>> platform.release()
'18.7.0'
>>> platform.version()
'Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64'
>>> platform.processor()
'i386'
>>> import sys
>>> sys.platform
'darwin'
>>> import socket
>>> socket.gethostname()
‘xxx021'
>>> socket.getfqdn()
‘xxx021'
>>>
Mac中Wine输出效果:
 ✘ ⚙ xxx@xxx  ~  wine python
002a:fixme:msvcrt:_configure_wide_argv (1) stub
002a:fixme:msvcrt:_initialize_wide_environment stub
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.uname()
uname_result(system='Windows', node=‘xxx021', release='XP', version='5.1.2600', machine='AMD64', processor='AMD64 Family 6 Model 142 Stepping 10, GenuineIntel')
>>> platform.machine()
'AMD64'
>>> platform.platform()
'Windows-XP-5.1.2600'
>>> platform.system()
'Windows'
>>> platform.release()
'XP'
>>> platform.version()
'5.1.2600'
>>> platform.processor()
'AMD64 Family 6 Model 142 Stepping 10, GenuineIntel'
>>> import sys
>>> sys.platform
'win32'
>>> import socket
>>> socket.gethostname()
‘xxx021'
>>> socket.getfqdn()
002a:err:winediag:WS_getaddrinfo Failed to resolve your host name IP
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>>>
注:
此处很明显:
platform.platform() == “%s-%s-%s” % (platform.system(), platform.release(), platform.version())

转载请注明:在路上 » 【已解决】Python中查看当前系统的硬件配置和系统平台和版本等系统信息

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.188 seconds, using 23.31MB memory