我多年来一直尝试运行我的代码,但它不断弹出此错误:
ModuleNotFoundError:没有名为“telegram”的模块
这是我的代码:
import telegram
api_key = "api_key"
user_id = "id"
class NotificationManager:
#This class is responsible for sending notifications with the deal flight details.
def __init__(self):
self.bot = telegram.Bot(token=api_key)
pass
def sendMessage(self, contents):
self.bot.send_message(chat_id=user_id, text=contents)
pass
此代码运行时应该在 Telegram 上向我发送一条消息。
我尝试了在网上找到的所有解决方案,包括:
pip3 install telegram
pip3 install python-telegram
pip3 install python-telegram-bot
一切都是最新的,包括 Python 和 Pip。我已经尝试卸载软件包并重新安装它们,但这没有帮助。
我什至尝试阅读该问题的中文和俄文解决方案,但他们也什么也没做(也许这只是谷歌翻译)。
编辑:
我正在尝试制作一个程序,向我的 Telegram 帐户发送消息。没有进一步的上下文。
ModuleNotFoundError
。仔细检查模块名称是否有拼写错误,并验证该模块是否已安装在您的 Python 环境中。如果没有安装,可以使用pip安装,例如:
pip install telegram
如果模块已安装但未找到,请确保您的 Python 环境配置正确,尤其是在您使用虚拟环境时。如果您仍然遇到问题,提供有关特定模块和上下文的更多详细信息可以帮助排除故障。
py - m pip install python-telegram-bot
或:
python -m pip install python-telegram-bot