About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi

Introduction

When I tried to handle the temperature / humidity sensor AM2302 on the Raspberry Pi with Python using the package Adafruit_DHT, an error occurred. The error at the time of installation can be avoided by performing a simple operation, but since the error that occurs when actually acquiring the temperature and humidity could not be avoided, the error was also avoided.

I confirmed that the error occurred on both Raspberry Pi 4B / 4GB on the computer, Raspbian lite on the OS, and Ubuntu Server 20.04, and Python installed 3.8.5 from pyenv and used Pipenv.

Error encountered

First of all, I try to install from pipenv obediently.

$ pipenv install Adafruit_DHT
Installing Adafruit_DHT…
Error:  An error occurred while installing Adafruit_DHT!
Error text: Collecting adafruit_dht
  Downloading Adafruit_DHT-1.4.0.tar.gz (15 kB)
Building wheels for collected packages: adafruit-dht
  Building wheel for adafruit-dht (setup.py): started
  Building wheel for adafruit-dht (setup.py): finished with status 'error'
  Running setup.py clean for adafruit-dht
Failed to build adafruit-dht
Installing collected packages: adafruit-dht
    Running setup.py install for adafruit-dht: started
    Running setup.py install for adafruit-dht: finished with status 'error'
---
Omission
---
✘ Installation Failed

I was able to confirm that the installation failed. Next, drop the package from GitHub, add a parameter indicating that the device you are using is a Raspberry Pi, and install it manually.

$ git clone https://github.com/adafruit/Adafruit_Python_DHT.git
$ cd Adafruit_Python_DHT
$ python setup.py install --force-pi
Finished processing dependencies for Adafruit-DHT==1.4.0

After confirming that the installation is complete, let's actually get the temperature.

$python
>>> import Adafruit_DHT
>>> Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/Projects/temp/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/home/pi/Projects/temp/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
    platform = get_platform()
  File "/home/pi/Projects/temp/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 63, in get_platform
    raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.

Will be.

Solution

Stop using Python 3.8.5 and use Python 3.7.9.

Commentary

Adafruit_DHT is a standard Python library for detecting the platform on which the package is used [Getting information from the platform](https://github.com/adafruit/Adafruit_Python_DHT/blob/master/Adafruit_DHT/platform_detect.py # L47). One of \ ('armv7l-with-debian','armv7l-with-ubuntu','armv7l-with-glibc2.4','armv7l-with-arch' ) in the platform specific information obtained here. Works if is included. At this time, the difference between the outputs of Python 3.8.5 and Python 3.7.9 was the cause of the error.

Below is the actual platform information confirmed from each Python version on Raspbian lite.

Python3.8.5

>>> import platform
>>> platforfm.platform()
'Linux-5.4.51-v7l+-armv7l-with-glibc2.28'

Python3.7.9

>>> import platform
>>> platforfm.platform()
'Linux-5.4.51-v7l+-armv7l-with-debian-10.4'

Digression

In the first place, the device called Beaglebone Black is aimed at detection in the above, and Raspberry Pi is [another place](https://github.com/adafruit/Adafruit_Python_DHT/blob/master/Adafruit_DHT/platform_detect.py# I am aiming for detection with L40). However, the Hardware item listed in / proc / cpuinfo on the Raspberry Pi 4B is BCM2711, which is not detected by this program.

Postscript

In the first place, the Adafruit_Python_DHT repository was currently archived and unmaintained. Instead, there is a Adafruit_CircuitPython_DHT repository, so please use this. For this person, Python 3.8.5 could be installed without any problem. However, please note that you cannot import it unless you also install the package called RPi.GPIO when using it. To use it, install Adafruit_CircuitPython_DHT and RPi.GPIO with the command below.

$ pip install adafruit-circuitpython-dht RPi.GPIO

Below is the case when trying to import adafruit-circuitpython-dht in an environment where RPI.GPIO is not installed.

>>> import adafruit_dht
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/temp/.venv/lib/python3.8/site-packages/adafruit_dht.py", line 34, in <module>
    from digitalio import DigitalInOut, Pull, Direction
  File "/home/pi/temp/.venv/lib/python3.8/site-packages/digitalio.py", line 15, in <module>
    from adafruit_blinka.microcontroller.bcm283x.pin import Pin
  File "/home/pi/temp/.venv/lib/python3.8/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 2, in <module>
    import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

Recommended Posts

About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
I want to run the Python GUI when starting Raspberry Pi
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
A story about trying to use cron on a Raspberry Pi and getting stuck in space
Use python on Raspberry Pi 3 to light the LED with switch control!
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
How to use the Raspberry Pi relay module Python
[python] A note when trying to use numpy with Cython
I get [Error 2055] when trying to connect to MySQL on Heroku
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Control the motor with a motor driver using python on Raspberry Pi 3!
Resolved an error when putting pygame in python3 on raspberry pi
A memo when connecting bluetooth from a smartphone / PC to Raspberry Pi 4
I want to use jar from python
Use the Grove sensor on the Raspberry Pi
Use BME280 temperature / humidity / barometric pressure sensor from Python on Raspberry Pi 2
A story I was addicted to when inserting from Python to a PostgreSQL table
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I get a UnicodeDecodeError when trying to connect to oracle with python sqlalchemy
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
[Hyperledger Iroha] Query with Python library
I wanted to use the Python library from MATLAB
I tried using the Python library from Ruby with PyCall
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
I created a Python library to call the LINE WORKS API
After researching the Python library, I understood a little about egg.info.
A story I was addicted to when inserting from Python to a PostgreSQL table
I want to prevent the speaker connected to the Raspberry Pi (jessie) from bouncing when the OS is restarted (Python script)
How to use Raspberry Pi pie camera Python
Sound the buzzer using python on Raspberry Pi 3!
Error when trying to install psycopg2 in Python
Connect to MySQL with Python on Raspberry Pi
I have a question. Unable to make protocol buffers on raspberry pi 3 modelB.
[Python] I want to know the variables in the function when an error occurs!
I want to use Python in the environment of pyenv + pipenv on Windows 10
I stumbled on the character code when converting CSV to JSON in Python
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
Use dHash to locate on the course from a scene in a racing game
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
About the handling of ZIP files including Japanese files when upgrading from Python2 to Python3
[Python] I tried to get the type name as a string from the type function
When I try to use Jupiter notebook on Mac, I can only select python2
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
From setting up Raspberry Pi to installing Python environment
Think about how to program Python on the iPad
A story that failed when trying to remove the suffix from the string with rstrip
[Python] I want to use only index when looping a list with a for statement
What to do when python3 type venv does not work well on Raspberry Pi
[Python] I made a system to introduce "recipes I really want" from the recipe site!
When I tried to do socket communication with Raspberry Pi, the protocol was different
I got stuck when trying to specify a relative path with relative_to () in python
A convenient function memo to use when you want to enter the debugger if an error occurs when running a Python script.
A story about a Python beginner trying to get Google search results using the API
When I try to import pandas on macOS I get the error No module named'_bz2'
How to pass arguments when invoking python script from blender on the command line
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
About the --enable-shared option when building Python on Linux
A memo of misunderstanding when trying to load the entire self-made module with Python3
Output to "7-segment LED" using python on Raspberry Pi 3!
A story about trying to introduce Linter in the middle of a Python (Flask) project
I want to use the R dataset in python
I get an error when I try to raise Python to 3 series using pyenv on Catalina
I want to be notified of the connection environment when the Raspberry Pi connects to the network
When I try to update the data on DynamoDB with Python (boto3), I get "ExpressionAttributeNames contains invalid key: Syntax error; key: <key name>"
Let's use AWS Lambda to create a mechanism to notify slack when the value monitored by CloudWatch is exceeded on Python
When creating a pipenv environment, I got addicted to "Value Error: Not a valid python path"
Use Heroku in python to notify Slack when a specific word is muttered on Twitter