dinkolubina
8/10/2017 - 11:39 AM

Import issues on when importing a module from a parent folder

Import issues on when importing a module from a parent folder

# prints the current working directory
os.getcwd()

# prints all the paths in python path
sys.path()

# To append a path

sys.path.append('')
sys.path.append('/new_path')
# Given a structure like:
# parent/
#   module/
#   myfolder/
#     my_script.py

# To avoid adding the current directory to path when running my_script.py.
# From parent/ run:

python -m myfolder.my_script 

# which will run with the current directory in the path