Reputation: 741
I have an application. Below is o/p of tree command -
app
|-- main
| |-- lib
| | |-- constants.py
| | |-- helper.py
| | `-- __init__.py
| `-- src
| |-- __init__.py
| `-- web.py
web.py
from flask import Flask, request
app = Flask(__name__)
from lib.helper import endpoints
.....
Some code
.....
if __name__ == '__main__':
app.run('0.0.0.0', 5433, debug=True)
I am getting this error
ImportError: No module named lib.helper.
where am I doing wrong?
Upvotes: 1
Views: 3528
Reputation: 3978
from flask import Flask, request
app = Flask(__name__)
import sys
from os.path import abspath, dirname
sys.path.insert(0, dirname(dirname(abspath(__file__))))
from lib.helper import endpoints
.....
Some code
.....
if __name__ == '__main__':
app.run('0.0.0.0', 5433, debug=True)
Upvotes: 1
Reputation: 157
Lib module is outside of src folder, need to go up one folder up and use that model.
from ..lib.helper
Upvotes: 0