Cannot import name, error from python-telegram-bot

Viewed 5629

I am trying to push my app with practically zero changes, just added a file that isn't involved in the app for now. Yesterday the app worked fine but now when I try to push the new version I get this error:

2020-02-29T15:26:39.875071+00:00 heroku[web.1]: State changed from crashed to starting
2020-02-29T15:26:43.028851+00:00 heroku[web.1]: Starting process with command `python costanti.py`
2020-02-29T15:26:44.744355+00:00 heroku[web.1]: State changed from starting to crashed
2020-02-29T15:26:44.729594+00:00 heroku[web.1]: Process exited with status 1
2020-02-29T15:26:44.668773+00:00 app[web.1]: Traceback (most recent call last):
2020-02-29T15:26:44.668795+00:00 app[web.1]: File "costanti.py", line 1, in <module>
2020-02-29T15:26:44.668918+00:00 app[web.1]: from telegram.ext import Filters,CommandHandler,MessageHandler
2020-02-29T15:26:44.668921+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site- packages/telegram/ext/__init__.py", line 25, in <module>
2020-02-29T15:26:44.669051+00:00 app[web.1]: from .callbackcontext import CallbackContext
2020-02-29T15:26:44.669054+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/telegram/ext/callbackcontext.py", line 21, in <module>
2020-02-29T15:26:44.669186+00:00 app[web.1]: from telegram import Update
2020-02-29T15:26:44.669189+00:00 app[web.1]: ImportError: cannot import name 'Update'

The app should be a telegram bot, and it worked for months until now, and I just can't understand why it isn't working on Heroku, but it works for me. I can think about PyCharm adding libraries to my requirements.txt. In fact when I use:

from telegram.ext import something

PyCharm underlines telegram telling me to add it to the requirements, but the actual library name is python-telegram-bot, not telegram. So maybe PyCharm added the name to the requirements and Heroku installed it, so when it says ImportError: cannot import name 'Update' it's actually looking for it in the telegram library, not in python-telegram-bot. Now I removed the library telegram from requirements but it still doesn't work.

It sounds strange to me, but this is the only reason I could find to this problem since the program runs on my pc, and the code in File "costanti.py", line 1 didn't change, and also because the problem comes from the library files.

1 Answers

In my requirements.txt I removed the telegram dependency.

I removed telegram==0.0.1

e.g I now have only 3 dependencies left, which are

python-telegram-bot==12.4.2
requests==2.22.0                                     
urllib3==1.25.7                
Related