'No module named 'telegram' error after installing python-telegram-bot

I have installed the python-telegram-bot from cmd using this: pip install python-telegram-bot and also I tried this pip install telegram

but after I run a code using Visual studio I receive this error message:

  • Message=No module named 'telegram'

and Visual studio highlight this line of code : import telegram.ext

I have tried installing python-telegram-bot several times So I entered cmd and I used pip install python-telegram-bot and also pip install python-telegram-bot --upgrade and also pip install telegram but it does not work I think I have to install it for Visual Studio somehow



Solution 1:[1]

telegram and python-telegram-bot are not the same packages. In fact, the telegram package is just namesquatting and it doesn't contain any functionality - see https://github.com/pypa/pypi-support/issues/1252 for details. So be sure to uninstall telegram via pip uninstall telegram -y and then install ptb via pip install python-telegram-bot.

Now to your actual problem: The editor highlighting import telegram.ext is rather surely a false positive. This is due to the pypi project being named python-telegram-bot while the library provides a package called telegram. Your editor probably just can't make that connection and thinks that the telegram package is not available.

If you get actual exceptions at runtime - i.e. python my_script.py raises exceptions about the telegram package missing - you'll need to double check that you installed PTB to same same python version/environment that you use to run the script.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CallMeStag