I've written a group of functions that I wanted to use for my computation and I've organize them in some .py file, say functions1.py
and functions2.py
. Within the same folder I have also another file main.py
, then:
root\
- functions1.py
- functions2.py
- main.py
Inside functions1.py
suppose I have the following code:
import numpy as np
def mycos(x):
return np.cos(x)
def mysin(x):
return np.sin(x)
While inside functions2.py
:
from .functions1 import mysin, mycos
def mytan(x):
return mysin(x)/mycos(x)
Now suppose that main.py
contain:
import numpy as np
from .functions2 import mytan
angle = np.pi/3
if mytan(angle) == np.tan(angle):
print('OK')
Then, If I execute main.py
I got the following error:
Traceback (most recent call last):
File "functions2.py", line 6, in <module>
from .functions1 import mysin, mycos
ImportError: attempted relative import with no known parent package
Did I miss something in the use of relative import?