Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect 64bit OS (windows) in Python

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

like image 645
williamtroup Avatar asked Feb 05 '10 16:02

williamtroup


People also ask

How do I tell if I have 64-bit Python?

1915 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> If the python is a 64-bit version, then it will display the below text ( MSC v. 1916 64 bit (AMD64) ) when you run the python command.

Does Python support 64-bit?

Python.org offers a number of different incarnations of Python for Windows. In addition to the 32-bit (“x86”) and 64-bit (“x86-64”) versions already mentioned, you can choose from the embeddable zip file, the executable installer, and the web-based installer.

Is my Python 32 or 64-bit Windows?

Python Version Bit – Does My Python Shell Run 32 Bit or 64 Bit Version? To check which bit version the Python installation on your operating system supports, simply run the command “ python ” (without quotes) in your command line or PowerShell (Windows), terminal (Ubuntu, macOS), or shell (Linux).


2 Answers

I think the best solution to the problem has been posted by Mark Ribau.

The best answer to the question for Python 2.7 and newer is:

def is_os_64bit():     return platform.machine().endswith('64') 

On windows the cross-platform-function platform.machine() internally uses the environmental variables used in Matthew Scoutens answer.

I found the following values:

  • WinXP-32: x86
  • Vista-32: x86
  • Win7-64: AMD64
  • Debian-32: i686
  • Debian-64: x86_64

For Python 2.6 and older:

def is_windows_64bit():     if 'PROCESSOR_ARCHITEW6432' in os.environ:         return True     return os.environ['PROCESSOR_ARCHITECTURE'].endswith('64') 

To find the Python interpreter bit version I use:

def is_python_64bit():     return (struct.calcsize("P") == 8) 
like image 175
phobie Avatar answered Sep 24 '22 16:09

phobie


I guess you should look in os.environ['PROGRAMFILES'] for the program files folder.

like image 30
Jochen Ritzel Avatar answered Sep 26 '22 16:09

Jochen Ritzel