I have a python project. The folder structure is like the following:
????src
┣ ????utils
┃ ┣ ????custom_pow.py
┃ ┣ ????equation.py
┃ ┗ ????__init__.py
┣ ????app.py
┗ ????__init__.py
custom_pow.py
class Pow:
def __init__(self,a,n):
self.a = a
self.n = n
def pow(self):
out = self.a ** self.n
return out
equation.py
from src.utils.custom_pow import Pow
class CustFormula:
def __init__(self,a,b):
self.a = a
self.b = b
def apbwsq(self):
ap = Pow(self.a,2)
bp = Pow(self.b,2)
out = (ap.pow()) + (2*self.a*self.b) + (bp.pow())
return out
def apbwcub(self):
aap = Pow(self.a,3)
bbp = Pow(self.b,3)
ap = Pow(self.a,2)
bp = Pow(self.b,2)
out = (aap.pow()) + (bbp.pow()) + 3*ap.pow()*self.b + 3*bp.pow()*self.a
return out
app.py
from src.utils.equation import CustFormula
p = CustFormula(2,3)
out = p.apbwsq()
print(f"(2+3)^2 = {out}")
I am pretty new to Python packaging. As per my understanding if we put init.py it will be considered as a module.
But while I am running the app.py from the src folder I am getting the below error:
File "********module-testsrcapp.py", line 2, in <module>
from src.utils.equation import CustFormula
ModuleNotFoundError: No module named 'src'
Please help me to solve this.