【发布时间】:2019-12-20 01:10:31
【问题描述】:
我正在开发一个树莓派 python 项目,每次导入一个包时,我都会收到相同的错误ModuleNotFoundError: No module named ''。例如我正在尝试添加ambient_api包
我按照他们的设置步骤进行操作:
pip install ambient_api
在我的文件顶部添加了导入:
from ambient_api.ambientapi import AmbientAPI
api = AmbientAPI()
但我得到了错误:
ModuleNotFoundError: No module named 'ambient_api'
我尝试添加的所有导入都会发生这种情况,我无法弄清楚我缺少什么。
当我在 google 上查找时,我发现 __init__.py 可能是一个解决方案,但我不确定它是如何工作的?
编辑:
here is what was output when I installed:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ambient_api in /home/pi/.local/lib/python2.7/site-packages (1.5.2)
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (from ambient_api) (2.21.0)
Requirement already satisfied: urllib3 in /usr/lib/python2.7/dist-packages (from ambient_api) (1.24.1)
我的终端中的版本: pi@raspberrypi:~/Raspberry-Pi-Greenhouse $ python --version Python 2.7.16
但是当我运行程序时,它看起来像 ide 中的 shell 版本在说: Python 3.7.3 (/usr/bin/python3)
【问题讨论】:
-
您使用哪个 python 版本安装包?在执行脚本的地方使用同一个 python?
-
脚本的文件名是什么?
-
@JaFizz 我正在使用 pyhton 2.7.16
-
this answer I wrote once 能解决您的问题吗?
-
注意:Python2 的生命周期即将结束。使用 Python3 安装和运行你的代码
标签: python raspberry-pi