Does anyone know how I would go about detected what bit version Windows is under Python. I need to know this as a way of using the right folder for Program Files.
Many thanks
Does anyone know how I would go about detected what bit version Windows is under Python. I need to know this as a way of using the right folder for Program Files.
Many thanks
I guess you should look in os.environ['PROGRAMFILES']
for the program files folder.
>>> 2**63-1 == sys.maxint
True
For 64 bit, and
>>> 2**31-1 == sys.maxint
True
For 32 bit.
There should be a directory under Windows 64bit, a Folder called \Windows\WinSxS64
for 64 bit, under Windows 32bit, it's WinSxS.
Hope this helps, Best regards, Tom.
platform
module -- Access to underlying platform’s identifying data
>>> import platform
>>> platform.architecture()
('32bit', 'WindowsPE')
Can anyone running 64-bit Windows tell us what 32-bit python running on 64-bit Windows returns?
You should be using environment variables to access this. The program files directory is stored in the environment variable PROGRAMFILES
on x86 Windows, the 32-bit program files is directory is stored in the PROGRAMFILES(X86)
environment variable, these can be accessed by using os.environ('PROGRAMFILES')
.
Use sys.getwindowsversion()
or the existence of PROGRAMFILES(X86)
(if 'PROGRAMFILES(X86)' in os.environ
) to determine what version of Windows you are using.
The subject lines asks about detecting 64 or 32bit OS, while the body talks about determining the location of ProgramFiles. The latter has a couple of workable answers here. I'd like to add another solution generalized to handle StartMenu, Desktop, etc. as well as ProgramFiles: http://stackoverflow.com/questions/2216173/how-to-get-path-of-start-menus-programs-directory
Many of these proposed solutions, such as platform.architecture(), fail because their results depend on whether you are running 32-bit or 64-bit Python.
The only reliable method I have found is to check for the existence of os.environ['PROGRAMFILES(X86)'], which is unfortunately hackish.