I have a custom Python package (my_package) located in a directory (super_dir). I have a script (my_script.py) in a nested directory of super_dir (let's call it sub_dir) that imports my_package and uses it.
I receive a ModuleNotFound error if I run the script from a terminal window (where my working directory is super_dir) by calling python sub_dir/my_script.py. It does work, however, if my_script.py is located within super_dir, rather than within sub_dir and I simply call python my_script.py. It also works if I run my_script.py in VSCode in the Python Interactive window (even if I'm my working directory is sub_dir) as long as I have the lines
import os
os.chdir('....further_paths/super_dir/')
at the top of the script.
My question is: how can I get the script to run from the terminal such that it can remain within sub_dir but will still be able to import my_package, even though my_package is located 'up' a whole directory?
Even if the lines^ above (that change the current directory) are included at the top of the script, I still get the ModuleNotFound error as long as I run the script from a terminal window and my_script.py is not located in super_dir.
Thank you in advance, I hope my question was clear!
super_dir/my_package.pyandsuper_dir/sub_dir/my_script.py?super_dir/my_package/init.pyandsuper_dir/my_package/my_functions.pysince there are modules and.pyfiles within the overarchingmy_package