AttributeError: module 'telegram' has no attribute 'Bot'
Asked Answered
W

5

10

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?

Wire answered 10/10, 2018 at 22:29 Comment(4)
How did you install the package? Notice that there are a number of Telegram related packages available at PyPI, and many of them do not have the API that you're looking for.Hebbe
Packages that give you the Bot class would be for example telegram-bot or python-telegram-bot, but we would need to know which one you intend to useHebbe
I did: "pip install telegram".Wire
As I understand it now I should have done: "pip install telegram-bot"? Or better inspect which package I download and use.Wire
P
17

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.
Prothonotary answered 13/1, 2019 at 10:12 Comment(1)
yup! I had to reinstall. Accidently I had installed telegram pip and uninstalled which seems to have messed up the python-telegram-bot package.Discontinuation
N
4

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:

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!

Nunley answered 10/10, 2018 at 22:53 Comment(0)
W
2

Note that your file name (.py) does not the same with your package name.

Withdrawn answered 11/9, 2019 at 18:50 Comment(1)
Dont name your file telegram.py or it wont work LOL this happened to me. Thanks!Twophase
C
2

I have faced the same issue and founded comment in releated GitHub issue that if you run code in test.py file you will have this issue. Maybe it will solve the issue for you.

Caerphilly answered 8/3, 2020 at 15:58 Comment(0)
M
0

If you're using PyCharm, and you're new to programming, to add the module, you need to add it to your project here: enter image description here

Mind answered 7/1, 2023 at 2:58 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Whitt

© 2022 - 2024 — McMap. All rights reserved.