Search code examples
flaskpythonanywhere

Flask site loads locally but fails on production (PythonAnywhere)


Yes, I have checked the errorimportingdebugging webpage that PythonAnywhere has.

The site runs locally, but fails in production.


Solution

  • If I understand your directory structure correctly, you want to import eAbsentee.admin from /home/eabsenteeproject/eAbsentee/eAbsentee/admin. However, Python will put the current working directory at the start of the system path, and the working directory will be your home directory on PythonAnywhere (unless you configure it differently on the "Web" page) so when trying to resolve the module name eAbsentee it will first look for a directory called /home/eabsenteeproject/eAbsentee. Because that exists, it won't search any further for that module and will try to find admin in there, which will fail. At that point you'll get that error.

    The best solution would be to make sure that your source code directory comes before the working directory in your system path -- do that in the WSGI file by replacing this:

    sys.path.append(path)
    

    ...with this:

    sys.path.insert(0, path)