ImportError: cannot import name 'ParseMode' from 'telegram'
Asked Answered
L

3

10

I am trying to create a telegram bot. The code i am trying to execute is :

from telegram import ParseMode

But it is throwing up this error:

ImportError: cannot import name 'ParseMode' from 'telegram'
(C:\ProgramData\Anaconda3\lib\site-packages\telegram\__init__.py)

Could you please advise how to fix this error?

Linzer answered 12/9, 2021 at 23:1 Comment(0)
O
2

you have to import with this way:

from telegram.ext import ParseMode

if problem not solved:

install the package like this:

pip install python_telegram_bot

or

pip install "python_telegram_bot==12.4.2"

Ofori answered 12/9, 2021 at 23:23 Comment(7)
Thanks for your response. I am still getting an error: ImportError: cannot import name 'ParseMode' from 'telegram.ext'Linzer
did you try to install last version of telegram? or uninstall the package and install that with this commands? pip install python_telegram_botOfori
I installed it and it imported in wellOfori
i used pip install telegram and i was able to import import telegram.ext just not parsemode. Should i uninstall it ?Linzer
yes uninstall the telegram and install python_telegram_botOfori
i uninstalled it and install python_telegram_bot but i am still getting the same message. Just to be sure also restarted the kernalLinzer
This answer is misleading at least. [ParseMode ](python-telegram-bot.readthedocs.io/en/stable/…) is clearly not contained in the telegram.ext package. Also python-telegram-bot is by now on version 13.7. Older versions don't get bug fixes and v13 introduced breaking changes. Finally, the project is named python-telegram-bot, not python_telegram_bot. While pip apparently converts _ to - due to naming conventions, this may not be the case with other package managers or future pip versions. Disclaimer: I'm currently the maintainer of PTB.Dharma
E
19

as per Version 20 you need to use:

from telegram.constants import ParseMode
Evolve answered 24/10, 2022 at 11:3 Comment(0)
O
2

you have to import with this way:

from telegram.ext import ParseMode

if problem not solved:

install the package like this:

pip install python_telegram_bot

or

pip install "python_telegram_bot==12.4.2"

Ofori answered 12/9, 2021 at 23:23 Comment(7)
Thanks for your response. I am still getting an error: ImportError: cannot import name 'ParseMode' from 'telegram.ext'Linzer
did you try to install last version of telegram? or uninstall the package and install that with this commands? pip install python_telegram_botOfori
I installed it and it imported in wellOfori
i used pip install telegram and i was able to import import telegram.ext just not parsemode. Should i uninstall it ?Linzer
yes uninstall the telegram and install python_telegram_botOfori
i uninstalled it and install python_telegram_bot but i am still getting the same message. Just to be sure also restarted the kernalLinzer
This answer is misleading at least. [ParseMode ](python-telegram-bot.readthedocs.io/en/stable/…) is clearly not contained in the telegram.ext package. Also python-telegram-bot is by now on version 13.7. Older versions don't get bug fixes and v13 introduced breaking changes. Finally, the project is named python-telegram-bot, not python_telegram_bot. While pip apparently converts _ to - due to naming conventions, this may not be the case with other package managers or future pip versions. Disclaimer: I'm currently the maintainer of PTB.Dharma
A
0

Was confronted with this recently, and what worked for me is:

from telegram import ParseMode
Alopecia answered 30/1 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.