Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 07:11 AM
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