Python脚本导入adafruit_dht时出现问题

1 python raspberry-pi

我正在运行树莓派 pi4b 并使用温度/湿度传感器。我在 pi 上有两个用户帐户:一个是“pi”,另一个是“will”。

当我在用户“pi”下运行以下代码时,它工作正常,当我使用“will”运行它时,它会出错:

Traceback (most recent call last):
  File "/tmp/pycharm_project_911/hum_temp.py", line 10, in <module>
    import adafruit_dht
ModuleNotFoundError: No module named 'adafruit_dht'
Run Code Online (Sandbox Code Playgroud)

我猜测用户“将”无法以某种方式adafruit_dht正确访问该库。任何人都可以阐明如何解决这个问题吗?

代码:

Traceback (most recent call last):
  File "/tmp/pycharm_project_911/hum_temp.py", line 10, in <module>
    import adafruit_dht
ModuleNotFoundError: No module named 'adafruit_dht'
Run Code Online (Sandbox Code Playgroud)

如果我尝试adafruit pip install按照“意愿”运行,我会得到:

Collecting Adafruit_DHT
  Using cached Adafruit_DHT-1.4.0.tar.gz (15 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: Adafruit-DHT
  Building wheel for Adafruit-DHT (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7ly2kmxi/adafruit-dht_34d224c3c67f4069a502b69fbcc56826/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7ly2kmxi/adafruit-dht_34d224c3c67f4069a502b69fbcc56826/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-v6u5rkri
       cwd: /tmp/pip-install-7ly2kmxi/adafruit-dht_34d224c3c67f4069a502b69fbcc56826/
  Complete output (1 lines):
  Could not detect if running on the Raspberry Pi or Beaglebone Black.  If this failure is unexpected, you can run again with --force-pi or --force-bbb parameter to force using the Raspberry Pi or Beaglebone Black respectively.
  ----------------------------------------
  ERROR: Failed building wheel for Adafruit-DHT
Run Code Online (Sandbox Code Playgroud)

小智 5

这不是一个完美的解决方案,但我遇到了同样的问题,并且能够通过使用以下命令使其工作sudo pip3 install Adafruit_DHT --install-option="--force-pi"