어떤 OS에서 실행 중인가요?

Windows 또는 유닉스 등을 사용 중인지 확인하려면 무엇을 확인해야 하나요?

질문에 대한 의견 (2)
해결책
>>> import os
>>> print os.name
posix
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'

플랫폼.시스템()`의 출력은 다음과 같습니다:

  • Linux: Linux
  • Mac: Darwin
  • Windows: Windows

참조: 플랫폼 - 기본 플랫폼의 식별 데이터에 대한 액세스 참조

해설 (6)

젠장, 브랜디가 저보다 먼저 시작했지만 그렇다고 해서 비스타에 대한 시스템 결과를 제공할 수 없다는 뜻은 아닙니다!

>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'Vista'

...그리고 아직 아무도 Windows 10에 대한 결과를 게시하지 않았다는 것이 믿기지 않습니다:

>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'10'
해설 (4)

참고로 다음은 Mac에서의 결과입니다:

>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Darwin'
>>> platform.release()
'8.11.1'
해설 (0)

39 의 샘플 코드를 사용하여 OS& 차별화합니다 파이썬.

from sys import platform as _platform

if _platform == "linux" or _platform == "linux2":
   # linux
elif _platform == "darwin":
   # MAC OS X
elif _platform == "win32":
   # Windows
elif _platform == "win64":
    # Windows 64-bit
해설 (5)

['시s.판포름'] (사용할 수도 있습니다 https://docs.python.org/library/sys.html # 시s.판포름) 시스템 ',' 이미 있는 경우 다른 모듈에서는 가져오기할 don& 진실이며당신이 임포트된 # 39 된 것입니다.

>>> import sys
>>> sys.platform
'linux2'
해설 (2)

그래도 확인표시를 사용자가 읽을 수 있는 구체적인 데이터를 사용할 수 있습니다. [판포맥플라포르마 ()] [1]

>>> import platform
>>> platform.platform()
'Linux-3.3.0-8.fc16.x86_64-x86_64-with-fedora-16-Verne'

[1]: http://docs.python.org/library/platform.html # 판포맥플라포르마

39 의 here& 틀렸다니까 위치를 식별할 수 있는 몇 개의 다른 통화를 할 수 있습니다.

import platform
import sys

def linux_distribution():
  try:
    return platform.linux_distribution()
  except:
    return "N/A"

print("""Python version: %s
dist: %s
linux_distribution: %s
system: %s
machine: %s
platform: %s
uname: %s
version: %s
mac_ver: %s
""" % (
sys.version.split('\n'),
str(platform.dist()),
linux_distribution(),
platform.system(),
platform.machine(),
platform.platform(),
platform.uname(),
platform.version(),
platform.mac_ver(),
))

이 출력은 실행했음 스크립트입니다 몇 개의 다른 시스템 (Linux, Windows, Solaris, MacOS) 및 아키텍처와의 (인타니움, 파워 pc, sparc, x86, x64) 를 사용할 수 있는 위치: https://github.com/hpcugent/easybuild/wiki/OS_flavor_name_version

우분투 12.04 서버 예를 들어 있습니다.

Python version: ['2.6.5 (r265:79063, Oct  1 2012, 22:04:36) ', '[GCC 4.4.3]']
dist: ('Ubuntu', '10.04', 'lucid')
linux_distribution: ('Ubuntu', '10.04', 'lucid')
system: Linux
machine: x86_64
platform: Linux-2.6.32-32-server-x86_64-with-Ubuntu-10.04-lucid
uname: ('Linux', 'xxx', '2.6.32-32-server', '#62-Ubuntu SMP Wed Apr 20 22:07:43 UTC 2011', 'x86_64', '')
version: #62-Ubuntu SMP Wed Apr 20 22:07:43 UTC 2011
mac_ver: ('', ('', '', ''), '')
해설 (0)

어때 새로운 대답:

import psutil
psutil.MACOS   #True (OSX is deprecated)
psutil.WINDOWS #False
psutil.LINUX   #False 

만약 내가 사용한 이 약간만이라도 출력물에는 MACOS

해설 (4)

나는 우리스트 도구를 사용하여 함께 제공되는 weblogic, 정보기술 (it), t # 39 구현하십시오 doesn& 플랫폼 패키지.

wls:/offline> import os
wls:/offline> print os.name
java 
wls:/offline> import sys
wls:/offline> print sys.platform
'java1.5.0_11'
def iswindows():
  os = java.lang.System.getProperty( "os.name" )
  return "win" in os.lower()
해설 (0)

자이썬 위한 유일한 방법은 내가 찾은 'os.name' 은 os 이름을 확인하는 jave 속성 (한 함께 '시스템', 'os' 와 '플랫폼' 에 대한 모듈에서는 자이썬 2.5.3 WinXP):

def get_os_platform():
    """return platform name, but for Jython it uses os.name Java property"""
    ver = sys.platform.lower()
    if ver.startswith('java'):
        import java.lang
        ver = java.lang.System.getProperty("os.name").lower()
    print('platform: %s' % (ver))
    return ver
해설 (1)

/usr/bin/python3.2

def cls():
    from subprocess import call
    from platform import system

    os = system()
    if os == 'Linux':
        call('clear', shell = True)
    elif os == 'Windows':
        call('cls', shell = True)
해설 (2)

좀 더 체계적인 시작했는데 열거합니다 뭐한테 값을 사용하여 다양한 모듈의 기대할 수 있습니다 (안심 편집할 수 있으며 추가 시스템이):

Linux (64bit) + 바슬

"' posix os.name 시s.판포름 linix linux*용 판포마리시스템 () linux-x86_64 sysconfig.get_platform () x86_64 판포마리마치니 () 판포마리아치티스투라 () (& # 39, & # 39, & # 39 64bit& # 39;;) "'

  • 함께 했던 아르크리눅스 및 민트, attaboy 동일한 결과를 접미사 '-' 는 ',' 에 의해 python2 시s.판포름 linux2 동일해집니다 계속 다른 모든 커널 버전 (예:
  • Windows 의 서브시스템과 동일한 출력을 linux*용 (함께 했던 unbuntu 18.04 LTS), '판포마리아치티스투라 제외한 () = (& # 39, & # 39, # 39 ELF& 64bit& # 39;;;)'

WINDOWS (64bit)

(32bit 열을 통해 실행 중인 32bit 서브시스템과)

"' 공식 파이썬 설치자는 64bit 32bit


os.name 전트 전트 win32 시s.판포름 win32 windows windo 판포마리시스템 () win32 amd64 windo sysconfig.get_platform () amd 64 AMD 64 판포마리마치니 () 판포마리아치티스투라 () (& # 39, & # 39 WindowsPE& # 39 64bit& # 39;;;;) (& # 39, & # 39 WindowsPE& # 39 64bit& # 39;;;;)

64bit msys2 32bit


posix posix os.name 시s.판포름 msys msys msys_nt-10.0 MSYS_NT-10.0-WOW 판포마리시스템 () msys-2.11.2-x86_64 msys-2.11.2-i686 sysconfig.get_platform () x86_64 i686 판포마리마치니 () 판포마리아치티스투라 () (& # 39, & # 39 WindowsPE& # 39 64bit& # 39;;;;) (& # 39, & # 39 WindowsPE& # 39 32bit& # 39;;;;)

msys2 mingw-w64-x86_64-python3 mingw w64 i686 python3


os.name 전트 전트 win32 시s.판포름 win32 windows windo 판포마리시스템 () mingw mingw sysconfig.get_platform () amd 64 AMD 64 판포마리마치니 () 판포마리아치티스투라 () (& # 39, & # 39 WindowsPE& # 39 64bit& # 39;;;;) (& # 39, & # 39 WindowsPE& # 39 32bit& # 39;;;;)

시그윈 64bit 32bit


posix posix os.name 시그윈 시s.판포름 시그윈 cygwin_nt-10.0 CYGWIN_NT-10.0-WOW 판포마리시스템 () cygwin-3.0.1-x86_64 cygwin-3.0.1-i686 sysconfig.get_platform () x86_64 i686 판포마리마치니 () 판포마리아치티스투라 () (& # 39, & # 39 WindowsPE& # 39 64bit& # 39;;;;) (& # 39, & # 39 WindowsPE& # 39 32bit& # 39;;;;)

"'

일부 비고:

또한 동일한 sysconfig.get_platform distutils.util.get_platform () '을' - '

  • windows on windows installer 은 파이썬 같은 공식 아나콘다
  • I have a Mac disk_b_s10database don& # 39, t do it 시스템 및 온라인 진정한 32bit 맞지 않았다.

단순히 비교할 수 있는 시스템과 함께 실행하십시오 스크립트입니다 (그리고 제발 덮어쓰기/추가 결과를 여기에 경우 누각되었습니다:)

"' print_function 충스러웠으니 future 가져오기의 가져오기의 os import sys 가져오기의 플랫폼 가져오기의 sysconfig

&quot 보기인쇄 (&quot, os.name, os.name) 보기인쇄 (시s.판포름 &quot 시s.판포름 ";) 보기인쇄 (&quot 판포마리시스템 &quot 판포마리시스템 () ();;) 보기인쇄 (&quot sysconfig.get_platform &quot sysconfig.get_platform () ();;) 보기인쇄 (&quot 판포마리마치니 &quot 판포마리마치니 () ();;) 보기인쇄 (&quot 판포마리아치티스투라 &quot 판포마리아치티스투라 () ();;) "'

해설 (0)

조심해, 여기서 'os.name' 는 're Windows 의 경우 시그윈 you& # 39 와 posix'.

>>> import os, platform
>>> print os.name
posix
>>> print platform.system()
CYGWIN_NT-6.3-WOW
해설 (0)

Windows 에서 흥미로운 결과가 8:

>>> import os
>>> os.name
'nt'
>>> import platform
>>> platform.system()
'Windows'
>>> platform.release()
'post2008Server'
해설 (0)

같은 맥락이다.

import platform
is_windows=(platform.system().lower().find("win") > -1)

if(is_windows): lv_dll=LV_dll("my_so_dll.dll")
else:           lv_dll=LV_dll("./my_so_dll.so")
해설 (2)

않을 경우 커널 버전을 찾고 있지만, 리눅스 배포판 등 찾고 사용할 수 있습니다 다음

python2.6+ 에서

>>> import platform
>>> print platform.linux_distribution()
('CentOS Linux', '6.0', 'Final')
>>> print platform.linux_distribution()[0]
CentOS Linux
>>> print platform.linux_distribution()[1]
6.0

python2.4 에서

>>> import platform
>>> print platform.dist()
('centos', '6.0', 'Final')
>>> print platform.dist()[0]
centos
>>> print platform.dist()[1]
6.0

물론 이 경우, 이렇게 하면 실행됩니까 linux 에서 사용할 수 있습니다. 좀 더 일반적인 스크립트입니다 할 경우 이 코드를 사용하여 주어진 샘플링합니다 플랫폼과 함께 사용할 수 있어 다른 분입니다.

해설 (0)

이거 드세요.

import os

os.uname()

및 만들 수 있습니다.

info=os.uname()
info[0]
info[1]
해설 (2)

윈도, OS 의 3 가지 방식으로 종류에 따라 각기 다른 pro 및 단점:

  • 메서드입니다 1*
>>> import sys
>>> sys.platform
'win32'  # could be 'linux', 'linux2, 'darwin', 'freebsd8' etc

이 작품을 어떻게 ([출처] [1]). Os 의 api 를 내부적으로 이 페이징됩니다 OS 가 정의한 확보하십시오 이름을 분명히 다른 버전으로 변경할 수 있기 때문에 사용하지 않는 것이 이 OS 를 직접. Here 지켜보리니 각종 운영체제별 값.

  • 메서드입니다 2*
>>> import os
>>> os.name
'nt'  # for Linux and Mac it prints 'posix'

이 작품을 어떻게 ([출처] [3]): 윈도 nt posix 는 내부적으로 경우 또는 불렀으매 운영체제별 모듈에서는 확인됩니다. 이러한 모듈 및 메서드를 호출할 수 있으며, 이 작품은 스케쳐내 임포트합니다 멋지구리해요. 단, 리눅스나 OSX 사이에 차별화된 없다.

  • 메서드입니다 3*
>>> import platform
>>> platform.system()
'Windows' # for Linux it prints 'Linux', Mac it prints `'Darwin'

이 작품을 어떻게 ([출처] [4]). 결국 OS 버전별 내부 OS api call it, get 내부적으로 # 39, & # 39 win32& 같이 이름. # 39, & # 39 또는 win16&. # 39, & # 39 또는 linux1&. # 39, & # 39 과 같은 이름의 정상화를 위해 후 좀 더 일반적인 Windows&. # 39, & # 39 또는 Linux&. # 39, & # 39 또는 Darwin&. 여러 적용하여 휴리스틱. 이 가장 좋은 방법은 이동형이든지 표준화된 OS 이름.

  • 夸약 *

Osx 리눅스, OS 는 Windows - 스케쳐내 여부를 확인할 수 있는 가장 확실한 방법은 판포마리시스템 () 또는 '다음'.

  • 그러나 운영체제별 페이징됩니다 하려면 '또는' os.name 'nt posix 내장현 파이썬 모듈' 를 통해 '다음'.
  • 스케쳐내 이름으로 OS 자체를 afaq 기초형상 OS 에서 제공하는 '다음' 시s.판포름.

[1]: https://github.com/python/cpython/blob/b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184/Python/sysmodule.c # L1478

[3]: https://github.com/python/cpython/blob/3.7/Lib/os.py # L48 [4]: https://github.com/python/cpython/blob/3.7/Lib/platform.py # L949

해설 (0)

플랫폼 및 시스템에 대한 답을 함께 사용할 수 있는 테스트 모듈에서는 인쇄인쇄 아웃해야 확인합니다.

import platform

print dir(platform)

for x in dir(platform):
    if x[0].isalnum():
        try:
            result = getattr(platform, x)()
            print "platform."+x+": "+result
        except TypeError:
            continue
해설 (0)

모든 정보를 확인할 수 있는 플랫폼 모듈 모듈에서는 임포트하지 않고 os 만 사용할 수도 있습니다.

>>> import platform
>>> platform.os.name
'posix'
>>> platform.uname()
('Darwin', 'mainframe.local', '15.3.0', 'Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64', 'x86_64', 'i386')

이를 통해 목적을 달성할 수 있는 좋은 깔끔한 레이아웃에 대한 보고 및 라인:

for i in zip(['system','node','release','version','machine','processor'],platform.uname()):print i[0],':',i[1]

이 주는 출력:

system : Darwin
node : mainframe.local
release : 15.3.0
version : Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64
machine : x86_64
processor : i386

하지만 어떤 누락되었습니다. 보통 운영 체제 버전 윈도우, 리눅스, 맥 플랫폼의 실행 중인 다운로드되었는지 합니다 인디펜덴트 방법은 이 테스트:

In []: for i in [platform.linux_distribution(),platform.mac_ver(),platform.win32_ver()]:
   ....:     if i[0]:
   ....:         print 'Version: ',i[0]
해설 (0)

이 솔루션은 모두 사용할 수 있다 '' 와 '자이썬'.

모듈을 os_identify.py :

import platform
import os

# This module contains functions to determine the basic type of
# OS we are running on.
# Contrary to the functions in the `os` and `platform` modules,
# these allow to identify the actual basic OS,
# no matter whether running on the `python` or `jython` interpreter.

def is_linux():
    try:
        platform.linux_distribution()
        return True
    except:
        return False

def is_windows():
    try:
        platform.win32_ver()
        return True
    except:
        return False

def is_mac():
    try:
        platform.mac_ver()
        return True
    except:
        return False

def name():
    if is_linux():
        return "Linux"
    elif is_windows():
        return "Windows"
    elif is_mac():
        return "Mac"
    else:
        return "" 

이렇게 사용합니다.

import os_identify

print "My OS: " + os_identify.name()
해설 (0)