시스템 운영 환경 정보 확인 with Python
아래 코드는 하드웨어 플랫폼 및 운영체제, 파이썬 환경을 출력한다.
# 시스템 운영 환경 정보 with Python
# by Sangmun Oh
# 참조: https://packaging.python.org/en/latest/specifications/dependency-specifiers/#dependency-specifiers
import os
import sys
import platform
def format_full_version(info):
version = '{0.major}.{0.minor}.{0.micro}'.format(info)
kind = info.releaselevel
if kind != 'final':
version += kind[0] + str(info.serial)
return version
def get_implementation_version():
if hasattr(sys, 'implementation'):
return format_full_version(sys.implementation.version)
else:
return "0"
# 하드웨어 플랫폼, 운영체제 정보, 파이썬 환경 출력
# implementation_name: cpython, jython
print(f"implementation_name : {sys.implementation.name}")
# implementation_version: 3.4.0, 3.5.0b1, 3.8.10,
print(f"implementation_version : {get_implementation_version()}")
# os_name: posix, java, nt
print(f"os_name : {os.name}")
# platform_machine: x86_64, AMD64, ...
print(f"platform_machine : {platform.machine()}")
# platform_release: 3.14.1-x86_64-linode39, 14.5.0, 1.8.0_51, 5.13-generic, 10
print(f"platform_release : {platform.release()}")
# platform_system: Linux, Windows, Java
print(f"platform_system : {platform.system()}")
# platform_version: # 10.0.22631,
# 1 SMP Fri Apr 25 13:07:35 EDT 2014
# Java HotSpot(TM) 64-Bit Server VM, 25.51-b03, Oracle Corporation
# Darwin Kernel Version 14.5.0: Wed Jul 29 02:18:53 PDT 2015;
# root:xnu-2782.40.9~2/RELEASE_X86_64
print(f"platform_version : {platform.version()}")
# python_full_version: 3.4.0, 3.5.0b1, 3.8.10, 3.9.13
print(f"python_full_version : {platform.python_version()}")
# platform_python_implementation: CPython, Jython
print(f"platform_python_implementation : {platform.python_implementation()}")
# python_version: 2.7, 3.4, 3.8, 3.10
print(f"python_version : {'.'.join(platform.python_version_tuple()[:2])}")
# sys_platform: win32, linux, linux2, darwin, java1.8.0_51
# (참고: linux는 Python3, linux2는 Python2)
print(f"sys_platform : {sys.platform}")
[실행 결과 예]
implementation_name : cpython
implementation_version : 3.9.13
os_name : nt
platform_machine : AMD64
platform_release : 10
platform_system : Windows
platform_version : 10.0.22631
python_full_version : 3.9.13
platform_python_implementation : CPython
python_version : 3.9
sys_platform : win32
'Python 기초' 카테고리의 다른 글
AttributeError: module 'bcrypt' has no attribute '__about__' (0) | 2024.12.12 |
---|---|
파이썬, 좌우 공백 문자와 제어 코드 문자 제거 (0) | 2024.09.27 |
pip download 명령 (0) | 2024.06.29 |
UnicodeEncodeError: 'ascii' codec can't encode character (0) | 2024.05.19 |
파이썬, 운영체제 이름과 버전 출력 예제 (0) | 2024.05.14 |