I'm encountering a problem with my Flask-based webapp. When I first joined PythonAnywhere, I went through the first walkthrough to create the database-powered comments webpage with source control via git. Felt good.
I then branched out to a personal project, but was lazy and didn't use git regularly. I created a virtual environment to get a newer version of a package and that all went well. The webapp worked as expected.
Yesterday, I went into that first walkthrough again to refresh my memory about how to use databases in python because I'd love to make use of them in my personal project. As I went through the instructions, I was ashamed as I remembered I had been neglecting source control, so I went ahead and did git commit
to get myself caught up.
Then the webapp stopped working. I now get an error:
2017-12-21 21:50:16,322: Error running WSGI application
2017-12-21 21:50:16,344: ModuleNotFoundError: No module named 'twilio.twiml.messaging_response'; 'twilio.twiml' is not a package
2017-12-21 21:50:16,344: File "/var/www/rclark010_pythonanywhere_com_wsgi.py", line 16, in <module>
2017-12-21 21:50:16,345: from flask_app import app as application
2017-12-21 21:50:16,345: File "/home/rclark010/quiksite/flask_app.py", line 98, in <module>
2017-12-21 21:50:16,345: from twilio.twiml.messaging_response import MessagingResponse
Again, the code worked before I committed. The virtual environment contains a newer version of Twilio (6.10.0) than the default PythonAnywhere Twilio package, which does not have the twilio.twiml package. That makes me think that my git commit screwed up the virtual environment somehow.
After some research online, I've found that when setting up a virtual environment, there are some steps one should take to make git and the virtual environment play nice. Something about pip freeze
and pip freeze > requirements.txt
and pip install -r requirements.txt
. I've seen different commands in different places, all without much explanation.
I neglected to do any of those steps before committing my code to git yesterday. (Ah, to be so young and naive.) My questions are:
- Is that likely the source of my error?
- If so, what's the best way to fix the situation? I think I can just delete the virtual environment and start fresh, but not sure if there is a more elegant solution
- Can you point me in the direction of a good guide that explains how to properly set up a virtual environment with source control for future reference? My searching thus far hasn't borne much fruit.
Thank you very much in advance for any help you might be able to provide! Cheers, Clark.