there's nothing deprecated about relative imports, but you should stick to a consistent working directory because that has a significant (yet non-obvious) effect on import statements
generally if you're making a package that can be used without installation, you should avoid using an src/ directory: py project/ โโโ package/ โ โโโ subpackage/ โ โ โโโ __init__.py โ โ โ from . import mod_a # Relative โ โ โ from package import mod_b # Absolute โ โ โโโ __main__.py โ โ โโโ mod_a.py โ โโโ __init__.py โ โ from . import subpackage # Relative โ โ from package import mod_b # Absolute โ โโโ mod_b.py โโโ main.py from package import subpackage to run main.py, you can simply use python path/to/main.py, but if you have to run the package or one of its submodules directly, your CWD determines how package can be imported, including your import statements, so you need to set your CWD to just outside package and run it with -m: sh /project $ python -m package.subpackage
as for installable packages, it's arguably simpler because your build system adds the package to your venv, for example: ```toml
project/
โโโ .venv/
โโโ src/
โ โโโ package/
โ โโโ subpackage/
โ โ โโโ init.py
โ โ โโโ mod_a.py
โ โโโ init.py
โ โโโ mod_b.py
โโโ pyproject.toml
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "my-project"
version = "1.0.0"
# Nothing else required, setuptools will find
# src/package by itself``` once you've installed your package into your environment, you can import it from anywhere regardless of CWD: ```sh
(.venv) /project $ pip install --editable .
...
Installed my-project-1.0.0
(.venv) /project $ cd /somewhere/else
(.venv) /somewhere/else $ python -c "import package" # Valid
(.venv) /somewhere/else $ python -m package.submodule # Valid```