I have a directory which contains a bunch of function and another folder which contains my main project which I would like to be able to run from the terminal: kf_sine_demo.py
.
When I run line by line the code from VS-Code (using Shift
+Enter
), everything works fine.
In particular I can import the functions for further use:
from EKFUKF_Py import lti_disc, kf_predict, kf_update, rts_smooth
However, when I run the file from the terminal:
python kf_sine_demo.py
I get the following error:
Traceback (most recent call last):
File "EKFUKF_Py/demo/kf_sine_demo/kf_sine_demo.py", line 16, in <module>
from EKFUKF_Py import lti_disc, kf_predict, kf_update, rts_smooth
ModuleNotFoundError: No module named 'EKFUKF_Py'
I see solutions which include specifying the full path. I have strong preference for relative imports.
UPDATE:
This solution has been most useful to me: https://stackoverflow.com/a/37193862/4576194.
- Run
python -m EKFUKF_Py.demo.kf_sine_demo.kf_sine_demo
form the parent directory ofEKFUKF_Py
But, that's not quite what I want. I want to be able to run python kf_sine_demo.py
from kf_sine_demo
directory and I want it to know that the functions it needs to import are located 2 levels up.