Is there an easy way to let a python program check if it running on the raspberry Pi or the pc running windows? I would like to use this to automaticly use the rpi.gpio functions in my code.

I am looking for a similair implementations as i use for debug modes:

if __debug__:
   import [some library]

I already found some examples that use os.uname(), but after testing this in python3 idle i found out that this was not working for me.

Does anybody know a good and simple way to implement this?

  • It is difficult to imagine any program requiring RPi.GPIO which would run on Windows. Although having said that you can access the Pi remotely using pigpio.
    – Milliways
    May 11, 2022 at 11:48
  • The project is with OpenCV and has some output via the gpio, but i am mostly testing the OpenCV part on my pc. since the pc does not have to use or can use rpi.gpio i would like to be able to run the code without commenting all rpio.gpio stuff out.
    – Rens
    May 11, 2022 at 14:07

1 Answer 1


Try sys.platform.

import sys

On my Linux laptop it reports linux2.

  • Thanks @joan, that solutions works great for me!
    – Rens
    May 11, 2022 at 14:55
  • @Rens: Please read this when you have a moment.
    – Seamus
    May 11, 2022 at 17:38
  • 1
    @Seamus i don't have the reputation to upvote it, but did accept the answer. Thanks for the reminder.
    – Rens
    May 12, 2022 at 14:05
  • @Rens: Huh! Didn't know rep was required to upvote, but I just upvoted your Q, so that moves you in the right direction :)
    – Seamus
    May 12, 2022 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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