mkdryden / telegram-stats-bot

A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.
GNU General Public License v3.0
53 stars 20 forks source link

ImportError: cannot import name 'Animation' from 'telegram' #9

Closed hndrk-themer closed 2 years ago

hndrk-themer commented 2 years ago

After running your bot like for over 7months without problem i cant start it anymore. I literally changed nothing.

I reinstalled like stated in readme, i even did the poetry way after i couldnt get it fixed, but nothing.

On Python 3.8:

ImportError: cannot import name 'TelegramError' from 'telegram' (....

on Python 3.9:

ImportError: cannot import name 'Animation' from 'telegram' (...

mkdryden commented 2 years ago

Interesting, there may have been a change in python-telegram-bot or something, though if you used poetry, it should use the poetry.lock file to use the specific versions. When I get a chance I will take a peek and see if I can reproduce it, though if you could give me the full traceback and what OS you're using, that might be helpful. As a quick stop-gap to get you back up and running, you might want to try the Docker version. If you use the 0.6.3 tag from my repository, that version was definitely working and should not have had any packages updated.

hndrk-themer commented 2 years ago

thanks! alright the bot is running again via docker ... i totally forgot that there is a docker image.

My Homeserver runs latest and fully updated Debian. As i said before i tested under Python 3.8 and Python 3.9.

Here is the complete Output:

Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/hendrik/.local/lib/python3.8/site-packages/telegram_stats_bot/main.py", line 31, in from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext, JobQueue File "/home/hendrik/.local/lib/python3.8/site-packages/telegram/ext/init.py", line 21, in from .dispatcher import Dispatcher, DispatcherHandlerStop, run_async File "/home/hendrik/.local/lib/python3.8/site-packages/telegram/ext/dispatcher.py", line 33, in from telegram import TelegramError ImportError: cannot import name 'TelegramError' from 'telegram' (/home/hendrik/.local/lib/python3.8/site-packages/telegram/init.py)

mkdryden commented 2 years ago

I have not been able to reproduce this on either Ubuntu or Windows with any Python version between 3.8 and 3.10, installing with either pip or Poetry, so I'm not sure what happened. Just in case, I have updated the python-telegram-bot requirement to the latest, in case some old version of it in your environment was causing the problem, and updated the poetry lock file to the latest compatible version of everything, in v0.6.4.

TheLexoPlexx commented 2 years ago

I stumbled upon this same error in Python 3.8 when I accidentally installed the python-telegram-bot alongside the telegram-package. Uninstalling both and reinstallong only the required one did the trick.

mkdryden commented 2 years ago

I stumbled upon this same error in Python 3.8 when I accidentally installed the python-telegram-bot alongside the telegram-package. Uninstalling both and reinstallong only the required one did the trick.

Ah, this makes sense. The telegram package seems to be some other defunct project with packages still on pypi and they share the same import names. I don't think there is any reason to use this package for anything, but I guess if you do, then it should be isolated from telegram-stats-bot by using a different venv/conda environment/etc.

ldhuy-proj commented 2 years ago

I stumbled upon this same error in Python 3.8 when I accidentally installed the python-telegram-bot alongside the telegram-package. Uninstalling both and reinstallong only the required one did the trick.

This really solved the problem for me, we only need the package python-telegram-bot