On a stock Jessie install, gpiozero works. E.g.

>>> from gpiozero.devices import pin_factory
>>> print(pin_factory)
<class 'gpiozero.pins.rpigpio.RPiGPIOPin'>

I then upgrade to gpiozero 1.4 with

sudo apt update
sudo apt full-upgrade

Which I'd like because the pinout command is super useful, and gpiozero is among the upgrade:

The following packages will be upgraded:
  bind9-host debconf debconf-i18n debconf-utils gtk2-engines-pixbuf
  libbind9-90 libc-ares2 libdns-export100 libdns100 libdvdnav4 libgcrypt20
  libgnutls-deb0-28 libgnutls-openssl27 libgtk2.0-0 libgtk2.0-bin
  libgtk2.0-common libirs-export91 libisc-export95 libisc95 libisccc90
  libisccfg-export90 libisccfg90 liblwres90 libsmbclient libtiff5 libwbclient0
  perl perl-base perl-modules python-gpiozero python3-gpiozero python3-thonny
  rpi-chromium-mods samba-common samba-libs xarchiver

But although pinout works (it's so cool!) nothing else does, e.g.

>>> from gpiozero.devices import pin_factory
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name pin_factory

And none of my python code with

from gpiozero import ...

Which used to work does either. For example, for

from gpiozero import DistanceSensor
ultrasonic = DistanceSensor( echo=17, trigger=4 )

which worked before doesn't. What happens now is that it sits for a while and then outputs 1.0 regardless of what's in front of the HC-SRO4. Any ideas? Any ideas? Thanks in advance!

  • Can you tell us what else doesn't work? There shouldn't be much from the basic functionality that doesn't work - perhaps you're doing something unsupported?
    – recantha
    Commented Jul 31, 2017 at 8:23
  • I updated the question to include an example with the HC-SR04 ultrasonic sensor. Thanks!
    – Dribbler
    Commented Jul 31, 2017 at 12:39
  • Try tweeting @ben_nuttall on Twitter - he helped write it and might know what the prob is.
    – recantha
    Commented Jul 31, 2017 at 17:23

1 Answer 1


The documentation for gpiozero shows that the way that you can change the default pin implementation has changed. Before, you changed the variable gpiozero.devices.pin_factory; now, you have to specify the GPIOZERO_PIN_FACTORY environment variable when starting Python. For example, instead of doing

from gpiozero.pins.native import NativePin
import gpiozero.devices
gpiozero.devices.pin_factory = NativePin

you need to start python like this:


and then gpiozero.Device.pin_factory changes to a NativeFactory object.

This is all taken from the documentation. Compare the documentation for pins for 1.4.0 and 1.3.2. The changelog should show you all of the other things that now should be done in a different way. Some things seem to have moved. gpiozero is not broken.

  • I looked through the documentation but coming from a mcu world to the pi, I'm still very much green here. Thanks super for your help. I got the pin factory working--at least to tell me about a pin--but what do I need to change in my HC-SR04 code in my updated post to get 1.4 to work? Thanks in advance!
    – Dribbler
    Commented Jul 31, 2017 at 12:41
  • @Dribbler I’m afraid that I don’t know much at all about gpiozero; I just checked the documentation to get this answer without really knowing much about the subject. Commented Jul 31, 2017 at 13:42

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.