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). This will open the interactive Python mode. The first line provides information whether it’s a 32 bit or 64 bit version.

Alternatively, you can also run the command “py” if the command “python” is not in your environment variable on your Windows machine.

Here’s the output on my computer (PowerShell) that shows that Python runs in a 64-bit version in the part [MSC v.1928 64 bit (AMD64)]:

PS C:\Users\xcent> python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

And here’s a screenshot:

Python Version 64 Bit

Using sys.version

In some environments such as macOS or some Linux versions, you may not see the number of bits in the output. You can manually output this using the sys.version information.

>>> import sys
>>> sys.version
'3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]'

Arithmetic Way to Check Bit Version

You can also calculate it manually in a small two-liner Python script:

import struct
print(struct.calcsize("P") * 8)

The output is either "32" or "64" depending on whether you run a 32-bit or 64-bit Python version:

# Output: 
# "32" for a 32-bit installation, or "64" for 64-bit

Here’s the explanation of the arithmetic approach to calculate the Python bit version:

The struct module converts data between Python values and C structs using Python bytes objects. The string argument "P" represents a generic pointer in C. Here’s the gist: a pointer has 4 bytes on a 32-bit system, and 8 bytes on a 64-bit system. The calcsize() function calculates the number of bytes for the pointer and multiplies it with 8 because 4*8 = 32 for a 32-bit system and 8*8 = 64 for a 64-bit system. Thus, struct.calcsize("P") returns your “Python Bit Version”.

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!