ImportError: No module named application [duplicate]

2024/10/7 16:26:26

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
Answer

I think that with Python 2, you will have to put an empty

__init__.py 

file in your database directory

https://en.xdnf.cn/q/118805.html

Related Q&A

Detect keypress without drawing canvas or frame on tkinter [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 6…

regex to extract a set number of words around a matched word

I was looking around for a way to grab words around a found match, but they were much too complicated for my case. All I need is a regex statement to grab, lets say 10, words before and after a matched…

How do I make a minimal and reproducible example for neural networks?

I would like to know how to make a minimal and reproducible deep learning example for Stack Overflow. I want to make sure that people have enough information to pinpoint the exact problem with my code.…

Increase the capture and stream speed of a video using OpenCV and Python [duplicate]

This question already has answers here:OpenCV real time streaming video capture is slow. How to drop frames or get synced with real time?(4 answers)Closed 2 years ago.I need to take a video and analyz…

Getting Pyphons Tkinter to update a label with a changing variable [duplicate]

This question already has answers here:Making python/tkinter label widget update?(5 answers)Closed 8 years ago.I have a python script which I have written for a Raspberry Pi project, the script reads …

Can someone help me installing pyHook?

I have python 3.5 and I cant install pyHook. I tried every method possible. pip, open the cmd directly from the folder, downloaded almost all the pyHook versions. Still cant install it.I get this error…

What is the bit-wise NOT operator in Python? [duplicate]

This question already has answers here:The tilde operator in Python(10 answers)Closed last year.Is there a function that takes a number with binary numeral a, and does the NOT? (For example, the funct…

PyQt QScrollArea no scrollarea

I haveclass View(QtWidgets.QLabel):def __init__(self):super(View,self).__init__()self.cropLabel = QtWidgets.QLabel(self)self.label = QtWidgets.QLabel(self)self.ogpixmap = QtGui.QPixmap()fileName = rC:/…

svg tag scraping from funnels

I am trying to scrape data from here but getting error. I have taken code from here Scraping using Selenium and pythonThis code was working perfectly fine but now I am getting errorwait.until(EC.visibi…

Python search for multiple values and show with boundaries

I am trying to allow the user to do this:Lets say initially the text says:"hello world hello earth"when the user searches for "hello" it should display:|hello| world |hello| earthhe…