Forums

import error

Hi

I have a flask app that runs perfectly. I am trying to get a mirror site for this up and running as I want to use it for a slightly different purpose with a few tweaks. I have coped the files from the first app and uploaded them to the second app and used the same virtual environment. So as far as I can see, the second app should be a mirror image of the first app. However, I am getting an import error:

Error running WSGI application
ModuleNotFoundError: No module named 'application'
File "/var/www/www_exampal_co_uk_wsgi.py", line 17, in <module>
from application import app as application

As I have said, this code works perfectly in my first app, is there something I am doing wrong for the second app given the file structure and files are exactly the same? only one app used a folder [mysite] which is the working app and other used the folder [ep]. Please bear in mind this was a home project and I do not work as a programmer! You have permission to look at my files should you need to.

Thanks

Is application.py a module that is on the PATH and does it contain the Flask app object? Basically you should edit the WSGI configuration file so it matches your setup. If, for example, before the line from application import app as application you'd have something like

import sys

# add your project directory to the sys.path
project_home = '/home/damianreid/mysite'
if project_home not in sys.path:
    sys.path = [project_home] + sys.path

The WSGI would expect an /home/damianreid/mysite/application.py with an app object available (or, alternatively, /home/damianreid/mysite/application with __init__.py providing the app object). Check if that matches your web app structure and if not, adjust the WSGI config and reload the web app afterwards.

Hi, thanks for the reply. my WSGI shows the file path for the new folder for my new app: So my existing app uses the folder '/home/damianreid/mysite but by new app uses '/home/damianreid/ep

import sys

# add your project directory to the sys.path
project_home = '/home/damianreid/et'
if project_home not in sys.path:
sys.path = [project_home] + sys.path

# import flask app but need to call it "application" for WSGI to work
from application import app as application

The app object is provided by the init.py at /home/damianreid/ep/application The app runs ok when I run it on localhost using visual studio code. I must be missing something but just don't know what.

You're adding /home/damianreid/et to your path, but keep saying /home/damianreid/ep. Make sure you have the directory name correct.

Thank you very much Glenn, I just couldn’t figure it out.