Python:获取Windows OS版本和体系结构 [英] Python: get windows OS version and architecture
问题描述
首先,我不认为这个问题是
的重复在Python中检测64位OS(Windows)
因为恕我直言,它还没有得到彻底的回答.
First of all, I don't think this question is a duplicate of
Detect 64bit OS (windows) in Python
because imho it has not been thoroughly answered.
唯一的答案是:
使用
sys.getwindowsversion()
或存在PROGRAMFILES(X86)(如果在os.environ中,则为'PROGRAMFILES(X86)'
)
Use
sys.getwindowsversion()
or the existence of PROGRAMFILES(X86) (if 'PROGRAMFILES(X86)' in os.environ
)
但是:
- Windows环境变量
PROGRAMFILES(X86)
是否可靠?我担心任何人都可以创建它,即使它不存在于系统中. - 如何使用
sys.getwindowsversion()
来获取体系结构?
- Does the windows environment variable
PROGRAMFILES(X86)
reliable? I fear that anyone can create it, even if it's not present on the system. - How to use
sys.getwindowsversion()
in order to get the architecture?
关于 sys.getwindowsversion()
:
链接 http://docs.python.org/library/sys.html#sys.getwindowsversion
使我们进入 http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
但我看不到任何与体系结构相关的内容(32位/64位).
而且,返回的元组中的平台元素似乎与体系结构无关.
Regarding sys.getwindowsversion()
:
The link http://docs.python.org/library/sys.html#sys.getwindowsversion
leads us to http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx
but I don't see anything related to the architecture (32bit/64bit).
Moreover, the platform element in the returned tuple seems to be independent of the architecture.
最后一点:我正在寻找同时使用python 2.5和Windows XP(从Windows XP开始)的解决方案
One last note: I'm looking for a solution using both python 2.5 and a windows version starting at Windows XP
谢谢!
相关信息可在此处
http://msdn.microsoft.com/zh-cn/library/ms724340%28v = VS.85%29.aspx
但是我怎么能用python呢?
The relevant info is available here
http://msdn.microsoft.com/en-us/library/ms724340%28v=VS.85%29.aspx
but how can I get this with python?
Edit2:在具有32位python解释器的64位Windows上:
On a 64bit windows, with a 32bit python interpreter:
- os.environ ["PROCESSOR_ARCHITECTURE"]返回
- 'x86'
- ('32bit','WindowsPE')
推荐答案
这些变量在Windows上显示您当前的运行时状态:
These variables show your current runtime status on windows:
@rem Test environment using this table: @rem @rem Environment Variable 32bit Native 64bit Native WOW64 @rem PROCESSOR_ARCHITECTURE x86 AMD64 x86 @rem PROCESSOR_ARCHITEW6432 undefined undefined AMD64 @rem
这篇关于Python:获取Windows OS版本和体系结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!