'I'm having trouble running the python-telegram-bot Library sample code

I'm trying to use the example codes from the repository's beginners guide and the ready-made examples: wiki& examples

I can't run them because of some classes that can't be imported. I'm using Visual Studio and when debugging, find the following error

from telegram.ext import (
    Application,
    CallbackContext,
    CommandHandler,
    ConversationHandler,
    MessageHandler,
    filters,
)

gives this error

cannot import name 'Application' from 'telegram.ext'

Was it my mistake? I uninstalled and installed using pip, the error keeps showing up



Solution 1:[1]

I think you haven't installed it correctly .

try installing it with setup.py in order to do that just follow these steps

1- git clone "repository link"

2- cd python-telegram-bot

3- py setup.py install or python setup.py install

Your code has no problem. if you encountered and error while doing this please do comment.

Solution 2:[2]

You are installing the alpha version which has a lot of changes. To fix this issue:

  1. Uninstall PTB v20
  2. Install latest PTB stable version (which is version 13) using: pip install python-telegram-bot
  3. use this version of documentation for a tutorial on how to write your first bot.

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 aiden021
Solution 2 Javad Zahiri