skip to Main Content

Well, I’ve tried to run another’s person telegram bot on my computer, but got a mistake that:

Traceback (most recent call last):
  File "C:UsersDmitriyPycharmProjectspythonProjectMain.py", line 10, in <module>
    keyboard = telebot.types.ReplyKeyboardMarkup(True, True)
AttributeError: module 'telebot' has no attribute 'types'

I’ve tried to import types from telebot:

from telebot import types

But it didn’t actually helped. The strangest thing is that this code works on code owner’s computer.

What can this be about?

enter image description here

4

Answers


  1. You need to install python-telegram-bot f.e via pip

    pip install python-telegram-bot 
    

    then import it from telegram package

    from telegram import ReplyKeyboardMarkup
    

    and replace creation of ReplyKeyboardMarkup into this:

    keyboard = ReplyKeyboardMarkup(True, True)
    
    Login or Signup to reply.
  2. for like these errors … reinstall the library or use (–upgrade) when you install it !

    like this:

    pip uninstall telebot
    pip install pyTelegramBotAPI
    pip install pytelegrambotapi --upgrade
    

    Happy Coding!

    Login or Signup to reply.
  3. The problem is that telebot and pyTelegramBotApi are different libraries but they are both imported via import telebot. In fact, when you do from telebot import types you import it from pyTelegramBotApi, not from telebot.

    To fix the issue just type:

    pip uninstall telebot
    pip uninstall pyTelegramBotApi
    pip install pyTelegramBotApi
    

    It worked for me 🙂

    Login or Signup to reply.
  4. If you use PyCharm, then I advise you to do the following.

    1. Go to the directory of your project.
    2. In this directory, open the venvScripts directory (eventually you should get the following path venvScripts)
    3. Next, go to the command line along this path AND ONLY AFTER THAT WRITE the pip install pyTelegramBotAPI COMMAND ♥
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search