Is It Windows 32, or Windows 64?

This is a sticky situation for any developer: finding out if a system is running 32-bit (x86) or 64-bit (x64) Windows. Usually, developers try to make two versions of their application, x86 and x64. While most of the time, they release two separate builds (for various reasons, one may be that the libraries used are so different between bits it is best there are two versions), sometimes they try to make just one build that supports both flavors. Doing this in Python can be tricky, but fortunately, there is a solution.

While all code should be Python 2 and 3 compatible unless otherwise noted, any Exceptions are from Python 3.3+.

The platform Module

This module has functions to get various info about a computer and OS. One function in particular, platform.machine(), returns what bit (or architecture) the OS is.

You may think that using this function may be risky, as it could return the architecture of the Python interpreter or CPU instead. After all, the documentation has only two sentences on it. I though this too, so I wrote up this small snippet of code to run on various machines and see the result.

This script simply runs platform.machine(), and depending on the value it returns, prints the appropriate message. It was run on many Windows machines of various hardware, and the value it returned matched the Windows architecture of the machine. Even when it was run on a 32-bit copy of Windows using a 64-bit CPU, and it correctly reported it was 32-bit Windows.

Congratulations! You now know how to find out how to get the Windows architecture of a computer and successfully make 32- and 64-bit compatible programs! 😀

One thought on “Is It Windows 32, or Windows 64?

Triangular Reactions

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s