4

I would like to have the raspberry python3 pip packages (e.g. rpi.gpio, picamera) installed in non raspberry hardware (e.g. on my x86 Ubuntu based PC) so that tools like Visual Studio Code can provide helpful code completion while coding.

When I try to install picamera in Ubuntu (x86) I get a "ValueError: Unable to determine if this system is a Raspberry Pi" which makes sense. But I would like somehow to have at least the "header" files (if python had something like that) as to be able to code against the picamera API.

Is this possible, or is there a viable alternative?

yannisf
  • 141
  • 1
  • 4

1 Answers1

1

In general what you need to do is mock the Raspberry Pi specific libraries on your dev system. There are several ways to do this usually involving one of the following:

  • Use the Python Mock library (unittest.mock)
  • Manually update the sys.modules dictionary with the missing references
  • Create your own local stub module (ie gpio.py) to provide the missing references

A perhaps easier way in this case is to use the fake-rpi library available via pypi. It might not have everything you need yet, but can be a clean way to develop Python projects for the RasPi on non-Raspi systems. The library is being actively developed, and this is what it has so far:

  • Adafruit - LSM303(accelerometer)
  • GPIO - gpio pins
  • picamera - camera
  • RPi - PWM
  • smbus - i2c

Internally It is using the sys.modules dictionary modification approach.

John S
  • 359
  • 1
  • 7