Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a python script that uses sys.platform.startswith('linux') to test if it is on linux or not, but then I can't tell the difference between the x86/64 processor, and the raspberry pi's ARM processor.

The reason I need this, is to run an external script that's compiled for either mac, linux x86/64, or linux ARM for the raspberry pi.

From what I can tell, there's not really a unified way to tell that you are in fact running on a raspberry pi. Any help would be appreciated.

share|improve this question
Can you use os.uname() to obtain this information? – milancurcic Feb 24 '13 at 17:12
Will that work on all distros for raspberry pi? On raspbian wheezy, it seems to work. – jnesselr Feb 24 '13 at 17:30
up vote 8 down vote accepted

You can use Python's os module to obtain this information through uname:

import os

This function should provide platform and other information on most Linux or Unix-like distributions.

From the Python documentation:


Return a 5-tuple containing information identifying the current operating system. The tuple contains five strings: (sysname, nodename, release, version, machine). Some systems truncate the nodename to eight characters or to the leading component; a better way to get the hostname is socket.gethostname() or even socket.gethostbyaddr(socket.gethostname()).

Availability: recent flavors of Unix.

share|improve this answer
os.uname()[4][:3] == 'arm' – OrangeTux Jul 6 '13 at 13:09
Anyone who looks at this now, we ended up doing os.uname()[4].startsWith("arm") to check. – jnesselr Jan 26 '14 at 7:27
@jnesselr tiny typo, it is startswith, not startsWith. Thanks, it helped. – Nishant Oct 4 '14 at 9:49

This is more of a problem with the advent of the Pi 2 (which is not simple to distinguish from the Beaglebone Black). The highest level of detail is found in /proc/cpuinfo on Linux-based systems (the 'Hardware' line). Here's an example of parsing that, from the Adafruit GPIO code:


share|improve this answer
This sounds like the best answer to me, since I would have suggested testing /proc/cpuinfo. I've never seen the platform.py from adafruit before, but looking over it, it makes sense. Also if the file doesn't exist, you'll know it's not a linux based system. Thanks for this :). Have my +1. – Peter Feb 18 '15 at 4:35
I encountered this yesterday when trying to get py-gaugette working with my Pi2... it (currently) uses the platform module method that unfortunately fails with the Pi2 and will hopefully benefit from this as well. github.com/guyc/py-gaugette/issues/12 – MartyMacGyver Feb 18 '15 at 7:30

The best widely-applicable system-identifying information I have found has been with:


This appears to give the same output as the shell command uname -a. In most cases the returned output is essentially the same (a string instead of a 5-tuple) as that of os.uname().

The ones I've tested and found equivalent outputs are OSX 10.9.5, Ubuntu 14.04, and Raspbian (??) Wheezy. On a Synology NAS, though, I get more information from the platform._syscmd_uname('-a') version:

>>> os.uname()
('Linux', [hostname], '3.10.35', [...], 'x86_64')
>>> platform._syscmd_uname('-a')
'Linux [hostname] 3.10.35 [...] x86_64 GNU/Linux synology_cedarview_1813+'

Seeing "synology" in the output there identifies it as an environment where things behave unexpectedly.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.