# Raspberry Pi 疑难解答指南 本指南提供在 Raspberry Pi 设备上运行物联网项目时常见问题的解决方案。 它针对正在学习 IoT-For-Beginners 课程的初学者设计,但对一般 Pi 开发也很有用。 --- ## 1. 安装和依赖错误 ### ❗ `ModuleNotFoundError: No module named 'xyz'` 当所需的 Python 模块未安装时会发生此问题。 **解决方案** ```bash pip3 install Permission denied when running scripts Often caused by accessing GPIO, I2C or system hardware without elevated privileges. Quick fix: sudo python3 script.py Recommended fix (no sudo needed every time): sudo usermod -aG gpio,i2c,spi $USER sudo reboot 2. GPIO / I2C / SPI Not Working ❗ RuntimeError: No access to GPIO Add user to GPIO group: sudo usermod -aG gpio $USER sudo reboot ❗ I2C / SPI devices not detected Enable interfaces: sudo raspi-config → Interface Options → Enable I2C / Enable SPI Check if I2C device appears: i2cdetect -y 1 3. Camera / Video Issues ❗ Camera not detected or fails to start Enable camera interface: sudo raspi-config → Interface Options → Camera → Enable sudo reboot Check if camera is visible: vcgencmd get_camera 4. Wi-Fi / SSH / Connectivity Problems | Problem | Fix | | -------------------------------- | --------------------------------------------- | | SSH connection refused | `sudo raspi-config → Interface Options → SSH` | | Device not showing on network | Check IP using: `hostname -I` | | Slow Wi-Fi / unstable connection | Prefer 2.4 GHz band, update OS | | Unable to access Pi headless | Add `ssh` file to boot partition | 5. Performance Issues Raspberry Pi running slow / laggy Close unused applications Reduce background services Use Lite OS if no desktop needed Ensure sufficient power supply (5V/3A or better) Check CPU load: top htop Storage issues: sudo apt autoremove sudo apt clean df -h --- **免责声明**: 本文档使用人工智能翻译服务 [Co-op Translator](https://github.com/Azure/co-op-translator) 进行翻译。虽然我们力求准确,但请注意,自动翻译可能包含错误或不准确之处。以原始语言的文档为权威来源。对于重要信息,建议采用专业人工翻译。我们不对因使用本翻译而产生的任何误解或曲解承担责任。