0

I'm trying to setup a server in python anywhere but I'm facing module import errors

File "/home/Adejuwonlo/Twitter_Automation/./services/telegram_service.py", line 2, in <module
>
    from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton, ParseMode
ModuleNotFoundError: No module named 'telegram'
>>> 

Although I have set up my virtual environment correctly and I rain my main.py script in the console (It worked) but when I run Flask app it fails to import my modules

I have tried different method and also deleted the default venv then pip install virtualenv and created a new venv and then installed my requirements.txt but still the error doesn't get fixed.

1 Answer 1

0

I used pythonanywhere before years ago, I don't know if they use your virtual env on web production. So what you should do is to learn the python version of your Flask App, which is prompted to you while signing up and on the command line use that python version while installing your requirements.txt

Example: python3.9 -m pip install pyrebase4 --upgrade --user The user command is essential, else, some libraries might not function or get installed, on PythonAnywhere. Also if the python version which you installed modules with doesn't match the flask production, it won't import.

Note: put app.run function under if __name__ =="__main__": block, else it won't work.

My recommendation: Use a VPS, Ubuntu LTS. Use nginx gunicorn to setup your flask app. Plenty of tutorials.

Good luck, let me know if this solved the problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.