0

I'm new to the world of Raspberry Pi's, I have programming experience but am new to Python.

I just want to be able to develop and debug python code for a Raspberry Pi in a windows 7 or 11 environment using either Visual Studio or Thonny.

When debugging I keep getting Module not found error whether I use RPi.GPIO or GPIOZero.

Other than physically connecting to Pi is there any way around this error in a windows environment? Thanks for your help.

2
  • Why? By all means teach yourself basic python on Windows but forget physical programming. I actually write most of my code on a Mac but ftp to a Pi and test over ssh. Most of my Pi run headless. Commented Dec 18, 2024 at 20:58
  • You can try Mock libraries. Mock libraries can be used to avoid ModuleNotFoundError and simulate the behavior of RPi.GPIO or GPIOZero on your Windows machine. Commented Dec 19, 2024 at 18:12

1 Answer 1

0

For the gpiozero module it is possible. gpiozero has a class named MockFactory which mocks the GPIO pins. Or, plainly said: it generates fake pins in software. This allows to develop and test Python programs using gpiozero accessing the GPIO pins on machines other than the Raspberry Pi / machines with no physical GPIO pins. Of course the limitation is that can change the state of a GPIO pin, but of course you can not read (input) from a pin.

Using the MocFactory is explained in the gpiozero documentation: Link.

gpiozero is installable on Windows machines, simply use the common way via pip to install it. This in combination with the MockFactory class allows you to develop on a Windows computer Python code for the Raspberry Pi using the gpiozero module.

3
  • Thanks very much noisefloor! I appreciate you taking th etime to share your knowledge. Commented Dec 18, 2024 at 19:47
  • This answer assumes that you can install gpiozero on a Windows machine; unless you can explain HOW it is not helpful. Commented Dec 20, 2024 at 3:39
  • @Milliways : thanks for pointing out that the infotmation is missing that gpiozero runs on Windows. Info is added. Commented Dec 20, 2024 at 11:45

Your Answer

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