'Telebot' 没有属性 'types'

'Telebot' has no attribute 'types'

好吧,我已经尝试 运行 在我的计算机上发送另一个人的电报机器人,但出现了一个错误:

Traceback (most recent call last):
  File "C:\Users\Dmitriy\PycharmProjects\pythonProject\Main.py", line 10, in <module>
    keyboard = telebot.types.ReplyKeyboardMarkup(True, True)
AttributeError: module 'telebot' has no attribute 'types'

我尝试从远程机器人导入类型:

from telebot import types

但这实际上并没有帮助。最奇怪的是这段代码在代码所有者的电脑上运行。

这是关于什么的?

enter image description here

您需要通过 pip 安装 python-telegram-bot f.e

pip install python-telegram-bot 

然后从电报包中导入

from telegram import ReplyKeyboardMarkup

并将 ReplyKeyboardMarkup 的创建替换为:

keyboard = ReplyKeyboardMarkup(True, True)

对于类似这些错误...重新安装库或在安装时使用 (--upgrade)!

像这样:

pip uninstall telebot
pip install pyTelegramBotAPI
pip install pytelegrambotapi --upgrade

编码愉快!

问题是 telebotpyTelegramBotApi 是不同的库,但它们都是通过 import telebot 导入的。事实上,当您执行 from telebot import types 时,您是从 pyTelegramBotApi 导入它,而不是从 telebot.

要解决此问题,只需键入:

pip unistall telebot
pip uninstall pyTelegramBotApi
pip install pyTelegramBotApi

它对我有用:)