pyTelegramBotAPI import error: AttributeError: module ‘telebot’ has no attribute ‘TeleBot’
Under normal circumstances, Python script calls pyTelegramBotAPI module with “import”:
import telebotdef telebot_send(message):
bot = telebot.TeleBot(TOKEN)
bot.send_message(chat_id, message)
But sometimes a special error will occur: AttributeError: module ‘telebot’ has no attribute ‘TeleBot’. Two situations will result in this error.
- The same name python file called “telebot.py” exists under the same directory. “import telebot” will import the file rather than the module;
Solution
Rename the “telebot.py”.
2. A familiar module “telebot” also exists in Pypi. If someone wrongly installed it with “pip3 install telebot” instead of pyTelegramBotAPI, python script will import a different module that doesn’t have the attribute.
Solution
pip3 uninstall telebot
pip3 install pyTelegramBotAPI
Uninstalling the pyTelegramAPI is necessary, then reinstall the pyTelegramBotAPI module, it will working without attribute error.