I am new to Python so maybe this is not an appropriate question. I am working on a project on Python that will use GPIO functionalities of the raspberry Pi. Right now, I am developing the python code on my local windows environment. This is because it is faster to work this way for me. I have it in a git repository so that when I want to test the code I just log into my raspberry pi and pull the latest code found on the repository.

However, I want to implement the code that will interact with the raspberry pi GPIO pins. I have downloaded the GPIO python source: RPi.GPIO 0.5.11, but I do not know how to add it into my python project on windows in order to use the GPIO functionality.


You can't, RPi.GPIO only works on the Raspberry Pi.

  • thanks. i wil need to manually change the code on deploy. – Luis Becerril Aug 5 '15 at 7:09
  • 3
    @LuisBecerril If the Pi is networked you could use NFS/Samba to mount your PC's directory. I use a Linux PC and just export my code directory as /code on the Pi. Alternatively, if you are a programmer, you could use my pigpio Python module. A daemon runs on the Pi but the Python script can run on a Windows, Mac, Linux machine. – joan Aug 5 '15 at 7:36

If you are just looking to test the whole code and not worry about the actual pins (as windows machines don't have GPIO), then you can fake it. First, in your main python source directory, create a directory named "RPi". In that folder, put an empty text file named __init__.py. This lets python know the folder "RPi" is a package. Also in that folder put a text file named "GPIO.py". In that file put the following:

OUT = 1
IN = 1

def setmode(a):
   print a
def setup(a, b):
   print a
def output(a, b):
   print a
def cleanup():
   print 'a'
def setmode(a):
   print a
def setwarnings(flag):
   print 'False'

This puts a pretty blank attribute set that can answer some of the GPIO calls you would most likely be using. Of course, there is no way to actually check whether the calls worked, but you won't get error messages stating the module GPIO doesn't exist. It's pretty hacky, but I use it when I don't feel like ssh into my pi for some quick code updates. You can add any other GPIO attributes you may need.

  • this is actually quite a tidy, simple solution. – paddyg Jul 27 '16 at 11:03
  • The file name is wrong because it's been interpreted as markup. It should have two leading and trailing underscores e.g. __init__.py – elParaguayo Jul 27 '16 at 11:36

PyCharm is a great IDE for Python.

Hidden deep in the settings is a way by which you can download different libraries to import in your program. Anything, from the conventional numpy and kivy, to the Pi standard RPi.GPIO, to externally developed ones like pigpio (that's what I use on my Pi, because it has a daemon and doesn't get interrupted by the system processes).

You can get it on the JetBrains website. There's a free (they call it PyCharm Community) version, and a Pro version, both on the JetBrains website. I find the Community version satisfactory.

The downside is that it's not the most intuitive software, and it takes a while to find out how exactly you do stuff. But after a while, one finally gets the hang of it.

You can type your code on your PC using PyCharm, upload it, and then pull it on your Pi when you want to run it.

  • 1
    This answer does not provide any information how to install RPi libraries and thus should not be considered as a valid answer. Just plugging IDE does not provide solution. – stiebrs Mar 25 at 9:08

You could try gpiozero library instead of RPi.GPIO. It can be installed in your dev environment and tested in Pi.

protected by Darth Vader Jan 29 '18 at 16:47

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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