Problems with No module found when install everything correctly..

Hello, I am having issues launching my first web app using Flask. I believe I properly setup (manually) the web app using python 3.7, entered the proper directories for my virtualenv and my flask app.

Web App Settings

I have looked at many similar issues with "ModuleNotFoundError: No module named 'X' " and followed every possible solutions but can't seem to find a fix. The server logs as shown below:

Server Error Log

I have also verified that the modules were installed in the correct virtualenv directory with the proper python version (3.7). I also checked while inside my virtualenv directory that my pip -V is also 3.7 and checked if there are any accidental pymongo module installed using pip2.7 as well. The only pymongo installed using pip2.7 is done locally and not in my web app virtualenv directory (not sure if that affects anything but I'm guess no). I'm totally stuck here and any help would be greatly appreciated.

BASH console checking pymongo module

The import that is failing is the one for flask_pymongo, which is a separate module to the pymongo driver. You need to pip install Flask-PyMongo into your virtualenv too.

Thanks for the response giles. I did what you recommended as shown below. It met (most? if not all) the requirements while installing.

flask-pymongo installation msg

and now I am getting a new error as shown below.

flask-pymongo server error

On a different problem... I ran my flask app using python3.7 and it gave me another error with another module (flask_mail)! sigh... Am I doing something wrong? I read the link provided to me thoroughly. The file is in my virtualenv folder (not in it's own folder though) so I assume "import flask_mail" should work?

flask_mail module importing error flask_mail and flask_recaptcha directory

Moving forward... I tried removing the flask_mail importing and got flask_recaptch importing error...

flask_recaptcha error

Continuing... I removed import flask_recaptcha and then the newly installed flask-pymongo module (recommended by you) throws an error! Ahhhh!!!

flask_pymongo error

Sorry for jumping all over the place but to summarize, I am having two major issues importing and getting PyMongo module to work and now importing flask_mail module.

It looks like you've got a lot of things you need to install -- for example dnspython -- and it will probably take a while to track them down. A better option might be to use a requirements file. I'm guessing that you created the site locally or somewhere else, and are now trying to deploy it on PythonAnywhere. Is that right? If so, did you use a virtualenv for the original setup? Or do you happen to have a requirements.txt file that you created?

BTW I strongly advise you change the password on your Mongo instance -- it is visible in the screenshot above.

Also -- if you're connecting to a Mongo instance from inside PythonAnywhere, you'll need a paid account -- free accounts only have restricted Internet access, and can't use MongoDB's protocol to connect outwards.


Yes, I have noticed i posted my password for mongodb :x I changed it like 10 seconds after I posted all the pictures lol. And yes, I have created my web app locally and as this is my first project, I did the grave mistake of installing all my packages/modules in the main python folder (not using virtualenv).

I did not create a requirement.txt file. I will google how to create one but where do I go from there?

Yes, I read extensively about using MongoDB Atlas with pythonanywhere. I just did not want to upgrade to a paid account yet until I have figured out the few problems I have now :)

EDIT: does my pythonanywhere virtualenv folder name need to be the same name as my locally virtualenv folder name? Want to make sure to avoid another minor pathing issue.


Just in case you are still reviewing this post. I have figured the solution out. It works now and I have upgraded my account :)

I am stuck with having MongoDB Atlas work but I will have a separate post if I cannot find a solution anytime soon. Thank you for your help. You earned a new happy customer!

Nvm. I am still stuck with the same issue. My website was able to launch BUT only a few installed modules CANNOT be imported/used. I do not understand why. The rest of the modules work. To be specific...

flask_mail module cannot be found. flask_reCaptcha module cannot be found. flask_mongoengine module cannot be found. flask_pymongo module cannot be found.

Complete package list

The virtualenv path in the "Web" section of Pythonanywhere is set properly. I checked the sys.path location and not sure if the issue lies here?


Ah, I see the problem here. When you run your code from the editor, it's completely separate to running it from the setup you've done on the "Web" page.

Once you've set up a website on the "Web" page, your site is up and running. There's no need to run it from anywhere else -- either from a console or from the editor. It will be started up as soon as you set it up, and restarted when you reload it. Sometimes it might be shut down due to system maintenance, but it will always start up again automatically as soon as it receives a hit. If there are problems with the site, you can see the error stacktraces in the error log, which is linked from the "Web" page. The most recent error will be at the bottom.

Now, as to how this explains the errors you're getting when you run it (I think unnecessarily) from the editor -- because you could have multiple websites, each of which used a different virtualenv, the save and run button in the editor does not try to run it in any virtualenv -- it just doesn't know which one it should pick for the specific file you have open. So, it runs it outside the env -- hence the error message.

If you do need to run the website's code from the editor, perhaps for debugging purposes, then you can do so by clicking the "Bash console here" button that appears at the bottom of the file when it is freshly opened, and then using workon to access your virtualenv, and then python /path/to/


Ah, that makes total sense. I guess I was just concerned when I saw that after running into this issue "POST 500 (INTERNAL SERVER ERROR)" (as shown in chrome dev tool) while I tried to use my login/create user/other features that requires access to MongoDB Atlas. The picture below will show the error logs. I'm not sure if it has to do anything with connecting to MongoDB Atlas or not? The reason I am concerned is because I am also hosting locally and it works like a charm but hosting on Pythonanywhere, this problem occurs.

pymongo error

Here is my MongoDB Atlas setup as I found in other forum posts. Let me know if this is correct or not. If this is not a Pythonanywhere issue, let me know so I will direct my questions to stack overflow.

MongoDB Atlas setup

I'd certainly read that as an error connecting to MongoDB, yes. I see you've got all of the right stuff from our MongoDB help page in your connection code, so that all looks good to me. Is there some kind of IP whitelisting you need to do for your Mongo instance?

Yes, I realized I need to whitelist Pythonanywhere but I cannot locate my webapp's ip address anywhere. Any idea how to access that or other ways to whitelist? MongoDB accepts IP Address or CIDR Notation.

Right now we don't many any guarantees about the IP address you'll be using, apart from it being within the list of AWS addresses (which is a huge set of CIDRs and changes frequently -- not something you could usefully whitelist!).

If you're happy opening it up to the Internet as a whole, you can use the CIDR


Yes, I have done that for now. Thanks a bunch for helping me through this. You did an awesome job and I greatly appreciate it :)

No problem at all! Glad to help :-)