Forums

ModuleNotFoundError: No module named 'config'

I need help, i am trying to host my flask script and it keeps throwing this error meanwhile, this is error log

2022-12-28 07:27:55,166: Error running WSGI application
2022-12-28 07:27:55,169: ModuleNotFoundError: No module named 'config'
2022-12-28 07:27:55,169:   File "/var/www/chukwuemeka_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-12-28 07:27:55,169:     from app import app as application  # noqa
2022-12-28 07:27:55,170: 
2022-12-28 07:27:55,170:   File "/home/Chukwuemeka/mysite/app.py", line 2, in <module>
2022-12-28 07:27:55,170:     import config
2022-12-28 07:27:55,170: ***************************************************
2022-12-28 07:27:55,170: If you're seeing an import error and don't know why,
2022-12-28 07:27:55,171: we have a dedicated help page to help you debug: 
2022-12-28 07:27:55,171: https://help.pythonanywhere.com/pages/DebuggingImpor

here is my wsgi file:

project_home = '/home/Chukwuemeka/mysite'
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 app import app as application# noqa

my app.py file contains these imports from config.py and aicontent.py

from flask import Flask, render_template, request
import config
import aicontent

def page_not_found(e):
  return render_template('404.html'), 404

here is the content of my config,py

class Config(object):
    DEBUG = True
    TESTING = False

class DevelopmentConfig(Config):
    SECRET_KEY = "this-is-a-super-secret-key"

config = {
    'development': DevelopmentConfig,
    'testing': DevelopmentConfig,
    'production': DevelopmentConfig
}

## Enter your Open API Key here
OPENAI_API_KEY = '******************'

here is the content of my aicontent.py

import os
import openai
import config
openai.api_key = config.OPENAI_API_KEY

def openAIQuery (query):
    response = openai.Completion.create(
        model="text-davinci-003",
        prompt= query, 
        temperature=0.7,
        max_tokens=1000,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0)

    if 'choices' in response:
        if len(response['choices']) > 0:
            answer = response["choices"][0]["text"]
        else:
            answer = "Oops sorry, you beat DaVinci this time"
    else:
        answer = "Oops sorry you beat DaVinci this time"

    return answer

nb: app.py, config.py and aicontent.py are in the are in the root of /mysite directory

[edit by admin: formatting]

Can we take a look at your files? We can see them from our admin interface, but we always ask for permission first.