Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Cannot Find Libraries#4670

Unanswered
teoatess asked this question inQ&A
Feb 6, 2025· 4 comments· 5 replies
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!")

ifname == '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 athttps://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 ofpython -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 . importversion 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 ofpython-telegram-bot is still corrupted.
Please run

python -m pip uninstall telegram python-telegram-bot -ypython -m pip install -U python-telegram-botpython -m telegram

If that doesn't work, I would recommend to deletemy_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 freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@teoatess@Bibo-Joshi

[8]ページ先頭

©2009-2025 Movatter.jp