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.
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.
Stop using Python 3.8.5 and use Python 3.7.9.
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'
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.
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