python - 不断收到 python ModuleNotFoundError: No module named
问题描述
我正在研究一个树莓派 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'
我尝试添加的所有导入都会发生这种情况,我无法弄清楚我缺少什么。
当我在谷歌上查找时,我发现__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)
解决方案
正如@JaFizz 在Pytorch 中所解释的那样,安装但不工作 ubuntu 18.04它通过提供别名并正确安装到所需的 python 版本来解决(在同一台机器上安装了两个 python)
首先需要指定python的位置,例如:
alias python=/usr/local/bin/python3.6
然后安装它:
python pip install <package name>
推荐阅读
- php - 无法显示 PDF BLOB 并使用 FPDF 写入文本水印
- azure - Azure Pipelines - 将自定义变量设置为内部版本号
- javascript - 当一个组件重新渲染时,它里面的所有变量都重新定义了吗?
- bluetooth-lowenergy - 强制 BLE 广告使用公共 mac 地址
- android - Gradel 同步意外失败
- flutter - Flutter - 一个主页的多个主体
- r - 从报纸网站上抓取图像
- java - 正则表达式单字符用户名验证
- python - Python:__dict__ 显示类对象的类属性,即使 __init__ 内部的行为改变了类属性
- file - Flutter web - 显示应用程序中生成的 pdf 文件。(Uint8List 格式)