I have a Python3 script (readtemp.py) to read temperature and humidity of a DHT22. I'm using adafruit_dht module. it executes perfectly from terminal command line with:
python3 readtemp.py
or
./readtemp.py
At the head of the Python script I have:
#!/usr/bin/python3
import time
import board
import adafruit_dht
I put a line in Apache PHP:
$output = exec("python3 ./readtemp.py");
or
$output = exec("./readtemp.py");
or
$output = shell_exec("python3 ./readtemp.py");
or
$output = shell_exec("./readtemp.py");
and all work but when the page loads the Python script is executed but the import gets an error. In apache error.log:
Traceback (most recent call last):
File "./readtemp.py", line 4, in <module>
import adafruit_dht
ModuleNotFoundError: No module named 'adafruit_dht'
It looks like apache isn't letting python load an external module. Any ideas to get apache to allow python access the exeternal modules?
sudo pip3 ...
so that the module is available for all users? – Dougie Jan 07 '21 at 16:43