【问题标题】:" import telegram.ext ModuleNotFoundError: No module named 'telegram.ext'; 'telegram' is not a package" after installing python-telegram-bot\" import telegram.ext ModuleNotFoundError: No module named \'telegram.ext\'; \'telegram\' is not a package\" 安装 python-telegram-bot 后
【发布时间】:2022-11-01 15:43:31
【问题描述】:

嘿,我试图编辑一个电报机器人,但这个错误不断出现。” import telegram.ext ModuleNotFoundError:没有名为“telegram.ext”的模块; ‘电报’不是一个包裹”。 我的代码是这样的: -

import telegram.ext

with open('token.txt', 'r') as f:
    TOKEN = f.read()


def start(update, context):
    update.message.reply_text("Helllo")


updater = telegram.ext.Updater(TOKEN, use_context=True)
disp = updater.dispatcher

```
`
any help will be appreciated   

I've tried reinstalling python-telegram-bot.

【问题讨论】:

  • 确保您实际安装了python-telgeram-bot 库,并且您正在从安装它的相同(虚拟)python 环境运行脚本。还要确保您没有名为“电报”的文件或目录

标签: python-telegram-bot python-3.11


【解决方案1】:

可能您也安装了错误的电报包。一些 IDE 会自动安装软件包,它们会安装 telegram 而不是 python-telegram-bot

您应该找到错误的安装包并将其卸载。

搞清楚import telegram.ext上导入了什么包,可以在错误描述中找到。然后你应该卸载它,使用如下命令:

pip uninstall telegam

然后安装python-telegram-bot,如果没有安装:

pip install python-telegram-bot

【讨论】:

    猜你喜欢
    • 2023-01-22
    • 1970-01-01
    • 2021-12-20
    • 2021-02-07
    • 2023-01-09
    • 2022-06-30
    • 2023-04-03
    • 2021-09-10
    • 1970-01-01
    相关资源
    最近更新 更多