简体   繁体   中英

'import RPi.GPIO as GPIO' doesn't work, no matter what I do

I'm doing a program to read the temperature from the GPIO pins. Unfortunately an access to these always throws a ModuleNotFoundError: No module named 'RPi'.

I tried reinstalling them, but that didn't work.

Exception:

import RPi.GPIO as GPIO

Traceback (most recent call last):
  File "/home/pi/SensorModuleWebseite/venv/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/home/pi/SensorModuleWebseite/sensormoduleWebseite.py", line 1, in <module>
    from app import app
  File "/home/pi/SensorModuleWebseite/app/__init__.py", line 7, in <module>
    from app import routes
  File "/home/pi/SensorModuleWebseite/app/routes.py", line 3, in <module>
    import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

The modul name is RPi.GPIO

pip install RPi.GPIO

( pip install Modules, especially here RPi.GPIO

You are using virtual env (venv) that has different python version (3.7) and different packages than the one you installed the package on using pip (2.7).

Install the package in your virtual environment using the command as answered by @Sonny Black.

More info on creating, activating, and installing packages in virtual environment here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM