m997al
Contributor III

Hi.  This was a long-standing issue for me too.  This solution may not be what is desired, but it works perfectly for my needs.

In my python code, I have this structure:

if __name__ == '__main__':

    # directory structure where "mycode" is this code here, trying to import "mymodule"
    #  > main
    #    -- mymodule
    #    > subdir
    #      -- mycode

    # Get the current directory
    current_directory = os.getcwd()

    # Get the parent directory
    parent_directory = os.path.abspath(os.path.join(current_directory, '..'))

    # Add the parent directory to sys.path
    sys.path.append(parent_directory)

    from mymodule import myfunction