Issue
I have the following folder structure in my project
my_project
notebook
|-- some_notebook.ipynb
src
|-- preprocess
|-- __init__.py
|-- some_processing.py
__init__.py
Now, inside some_notebook.ipynb
I simply want to get the methods from some_processing.py
. Now we I run
from src.preprocess import some_processing
from some_notebook.ipynb
it always throws
ModuleNotFoundError: No module named 'src'
I found multiple questions regarding this and played around with sys.path.append(<path-to-src>)
. But I couldn't solve it. Which path do I provide? Something like ../src
didnt work?
I checked for example the AlphaFold project from DeepMind and they are using it also with this structure. I tried to replicate exactly like they did.
How can I solve this? Which path do I provide in sys.path.append()
?
I appreciate any help!
Solution
I found the answer. Running
sys.path.insert(1, os.path.join(sys.path[0], '../src'))
made it possible to import anything from parent module src
.
Answered By - PeeteKeesel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.