Relative imports for the trilliоnth time

Script vs. Module Here’s an explanation. The short version is that there is a big difference between directly running a Python file, and importing that file from somewhere else. Just knowing what directory a file is in does not determine what package Python thinks it is in. That depends, additionally, on how you load the … Read more

Python relative-import script two levels up

To access script_c and script_b from script_a, you would use: from …folder_3 import script_c from . import script_b Or if you use python3, you can import script_b from script_a by just using: import script_b However, you should probably use absolute imports: from mypackage.folder_3 import script_c from mypackage.folder1.folder2 import script_b Also see: Absolute vs Relative imports

Import local function from a module housed in another directory with relative imports in Jupyter Notebook using Python 3

I had almost the same example as you in this notebook where I wanted to illustrate the usage of an adjacent module’s function in a DRY manner. My solution was to tell Python of that additional module import path by adding a snippet like this one to the notebook: import os import sys module_path = … Read more

Relative imports – ModuleNotFoundError: No module named x

TL;DR: You can’t do relative imports from the file you execute since __main__ module is not a part of a package. Absolute imports – import something available on sys.path Relative imports – import something relative to the current module, must be a part of a package If you’re running both variants in exactly the same … Read more

Relative imports for the billionth time

Script vs. Module Here’s an explanation. The short version is that there is a big difference between directly running a Python file, and importing that file from somewhere else. Just knowing what directory a file is in does not determine what package Python thinks it is in. That depends, additionally, on how you load the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)