I have the following structure in my python project:
BASE_DIRECTORY
¦- data
¦- notebooks
¦ \
¦ ***here are the jupyter notebooks***
¦ __init__.py
¦ analysis.ipynb
¦
¦- src
¦ \
¦ ***here are further modules***
¦ __init__.py
¦ configuration.py
¦
I would like to import class Config() from configuration.py into a jupyter notebook analysis.ipynb.
I tried:
from ..src.configuration import Config
but that gives me a ValueError:
ValueError: attempted relative import beyond top-level package
Can someone direct how to achieve this? I would prefer to work with relative paths rather than with changing PATH variables.
I feel there are some specifics about Jupyter that I am not aware of, e.g. it seems to be harder to refer to the current path.
I saw that you said that you do not want to alter the path variables, but using sys to do this gives a solution:
import sys
sys.path.append('..')
from src.configuration import Config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With