I am running a flask application and connecting to database with Flask-mysqlAlchemy when I am running my script with python 2.7 I am getting below error.
Traceback (most recent call last):File "app2.py", line 8, in <module>from database.dbconfig import db, myAccounts2
ImportError: No module named database.dbconfig
whereas this is running fine in python3 I need this running in python 2.7 as my server is pre-installed with it. I am not able to figure out what the issue is. I have installed all dependencies in my server and keep getting this where as it works in my local machine with python3.
Here is my main script
My directory is like this
Main folder
|
+--->database
| |
| +------> dbconfig.py
|
+----->app2.py
Here is my app2.py
#!usr/bin/python
import boto3
import json
import urllib2
import urlparse
#import urllib.request
#import urllib.parse
from database.dbconfig import db, myAccounts2
from flask_sqlalchemy import SQLAlchemy
from flask import Flask,render_template,jsonify,json,requestapplication = Flask(__name__)
Here is my dbconfig.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemyapp = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/test_pb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS']= 'False'
app.config['SECRET_KEY'] = "random string22"
db = SQLAlchemy(app)class myAccounts2(db.Model):#__tablename__ = 'myAccounts'id = db.Column(db.Integer, primary_key=True)account_name = db.Column(db.String(45), primary_key=True)vpc = db.Column(db.String(55))subnet = db.Column(db.String(55))instance_type = db.Column(db.String(90))def __init__(self, account_name, vpc, subnet, instance_type):#self.id = idself.account_name = account_nameself.vpc=vpcself.subnet=subnetself.instance_type=instance_type