I have a telegram bot written using python-telegram-bot that was working fine but after a few weeks, when I start the script, it seems like it cannot find some libraries & modules.
As an example, "Update" is widely used in my code and it was working just fine. But now it cannot be found by python.
Here are some of my imports.
from telegram import Update, ForceReply, InlineQueryResultArticle, InputTextMessageContent, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup, Update, User, ReplyKeyboardMarkup, Contact, Message, KeyboardButton
And here is the error.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
NameError: name 'Update' is not defined
Does anyone know any solution?
I tried moving to a new environment, reinstalling python-telegram-bot with –pre or –upgrade switches, clearing the python cache and reloading the vs code ssh window.
2
Answers
I don’t think there is a good way to transfer environments to production (Correct me if I am wrong), however, you can build a new environment using the exact same packages that are installed in your environment using:
This saves every package you used in the development env in a file.
Then you can use this file in a docker file to build the exact same dependencies your bot was developed with, using:
I found the recommendation reistall dependency and it works for me. (Although PyCharm IDE still says "could not find reference", bot starts working fine):