I have a Python project with subdirectories and I'm unable to import a module located in the root directory, here logger.py
, from another module in a subdirectory, here composite.py
.
The problem is that logger.py
point to a log file in the log
directory with a relative path name to it, so composite.py
can't find this file from it's sub directory.
How can I import module logger
from composite.py
and from another module in the root directory, like module.py
?
├── data/
module.py
logger.py
├── composite/
│ ├── composite.py
├── log/
│ ├── info.log
This work :
data/logger.py:
h_info = RotatingFileHandler('log/info.log', [...])
data/module.py:
import logger
This doesn't work:
data/composite/composite.py:
from data import logger
FileNotFoundError: [Errno 2] No such file or directory: '/home/abc/project/python/xyz/data/composite/log/info.log'