I'm using python 3.6.X.
I have following tree structure:
BS/ BS.py test_BS.py SI/ SI.py I wish to import BS.py inside SI.py hence wrote:
import BSbut it's giving the error message:
File "SI.py", line 1, in <module>
import BS
ModuleNotFoundError: No module named 'BS' 1 2 Answers
import os, sys
#Following lines are for assigning parent directory dynamically.
dir_path = os.path.dirname(os.path.realpath(__file__))
parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir))
sys.path.insert(0, parent_dir_path)
import BS 1 You need to add your dir to the PYTHONPATH:
export PYTHONPATH="${PYTHONPATH}:/your/dir/BS" 3