user8569455
user8569455

Reputation: 31

Python Flask Heroku Cannot import module

I am getting the following error

"ModuleNotFoundError: No module named 'class1'"

Structure

- hello-world
   - src
       - __init__
       - main
       - class1
- Procfile

The main1 file looks like this:

from class1 import G

APP = Flask(__name__)
@APP.route('/', methods=['GET'])
def index() -> str:
    return 'We are alive'

Profile:

web: gunicorn src.main:app --log-file -

The heroku logs shows us the following errors:

ModuleNotFoundError: No module named 'class1'

I don't know what I am doing wrong. I am using pipenvto install dependencies and it contains gunicorn.

Upvotes: 2

Views: 1842

Answers (2)

Jay
Jay

Reputation: 93

should be like this

from hello-world.src.class1 import G

first rename your folder hello-world.. Python does not recognize operands to class name or folder name. it will return an error

Upvotes: -1

tupui
tupui

Reputation: 6528

You have to import the class using:

from .class1 import G

Do not forget the dot. When you build a package you have to tell where your class is written using this relative path. This is called intra-package references.

See the corresponding doc.

Upvotes: 3

Related Questions