Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'telegram' has no attribute 'Bot'

I am using python and getting this error.

  1. import telegram
  2. telegram.Bot(token = '###############')

When I run this, appears: "AttributeError: module 'telegram' has no attribute 'Bot'" Any ideas how to solve this?

like image 864
Duncan Jansen Avatar asked Oct 10 '18 22:10

Duncan Jansen


2 Answers

I assume you're referring to python-telegram-bot and that you solely use python-pip for package installation (and not your OS's package manager):

  1. Ensure that you don't have colliding telegram packages installed:
~> pip3 list | grep -i telegram
python-telegram-bot 11.1.0
  1. Force reinstall:
pip install --user --force-reinstall python-telegram-bot
  1. Ensure that you don't accidentally have a telegram.py within your project.
like image 96
Suuuehgi Avatar answered Sep 18 '22 11:09

Suuuehgi


It seems like you've installed the telegram package (according to the comments). Uninstall that one, and then you need to go and choose one that gives you the Bot class instead. For example:

  • python-telegram-bot
  • telegram-bot

Looks to me like the first one is more developed (the second one hasn't been touched in a while), but they have different licenses. Explore the options!

like image 33
Ricardo Cárdenes Avatar answered Sep 19 '22 11:09

Ricardo Cárdenes