Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Traceback (most recent call last):
File "/home/thomas/python/practice.py", line 2, in
from telegram import Update
ImportError: cannot import name 'Update' from 'telegram' (/home/thomas/python/my_test_environment/lib/python3.12/site-packages/telegram/init.py)

Following is my code:

import logging
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")

if name == 'main':
application = ApplicationBuilder().token('TOKEN').build()

start_handler = CommandHandler('start', start)
application.add_handler(start_handler)

application.run_polling()

I am doing my first tutorial on my first bot

You must be logged in to vote

Replies: 4 comments · 5 replies

Comment options

This is the tutorial

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions---Your-first-Bot

You must be logged in to vote
0 replies
Comment options

Hi. Please have a look at https://github.com/python-telegram-bot/python-telegram-bot/wiki/Frequently-Asked-Questions#why-am-i-getting-importerror-cannot-import-name-xy-from-telegram.

You must be logged in to vote
3 replies
@teoatess
Comment options

I continue to receive the same error.

(my_test_environment) thomas@elm:~/python$ python chatmember.py
Traceback (most recent call last):
File "/home/thomas/python/chatmember.py", line 17, in
from telegram import Chat, ChatMember, ChatMemberUpdated, Update
ImportError: cannot import name 'Chat' from 'telegram' (unknown location)

I have updated the $PATH and the $PYTHONPATH

I have uninstalled telegram and reinstalled python-telegram-bot

@Bibo-Joshi
Comment options

Please show me the output of python -m telegram

@teoatess
Comment options

homas@elm:/python$ source my_test_environment/bin/activate
(my_test_environment) thomas@elm:
/python$ python -m telegram
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/home/thomas/python/my_test_environment/lib/python3.12/site-packages/telegram/main.py", line 25, in
from . import version as telegram_ver
ImportError: cannot import name 'version' from 'telegram' (unknown location)
(my_test_environment) thomas@elm:~/python$

Comment options

all right, that means that the installation of python-telegram-bot is still corrupted.
Please run

python -m pip uninstall telegram python-telegram-bot -y
python -m pip install -U python-telegram-bot
python -m telegram

If that doesn't work, I would recommend to delete my_test_environment and set up a fresh venv instead.

You must be logged in to vote
1 reply
@teoatess
Comment options

damn i think this worked! Wow, thank you!

Comment options

So after I create this bot what can I do with it?

https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions---Your-first-Bot

You must be logged in to vote
1 reply
@Bibo-Joshi
Comment options

Uh .. whatever the bot API allows you to do. Have a look at the "bots built with PTB" wiki page for some inspiration. But this is a bit beyond the scope of the thread. I recommend joining our groups on telegram if you want to get some general comments from other PTB users :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
⁉️
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.