无法从telegram导入Chat类的ImportError问题解决求助
解决无法从'telegram'模块导入'Chat'类的问题
问题原因
你安装的第三方包不符合需求:python-telegram、telegram、telegram.chat都不是官方用于Telegram Bot开发的标准库,正确的依赖是python-telegram-bot,只有这个库包含你需要的Bot和Chat类。
具体解决步骤
- 先卸载错误安装的包:
pip uninstall -y python-telegram telegram telegram.chat
- 安装官方标准库:
pip install python-telegram-bot
- 验证导入:你代码里的
from telegram import Bot, Chat语句是正确的,无需修改,重新运行代码即可。
版本兼容提示
如果你的代码使用了Updater(如示例中的from telegram.ext import Updater),注意python-telegram-bot v20及以上版本已弃用Updater,若要保留原有代码逻辑,可以安装指定旧版本:
pip install python-telegram-bot==13.7
内容的提问来源于stack exchange,提问作者David
相关产品推荐
相关产品推荐

