I am pretty new here and would appreciate some help.
So lately, I have been using Jupyter notebook for some learning in this case, test out function that I made from a different folder.
Originally, the structure is as follows:
/Main Folder
/ Library(containinng function)
Notebook
In this structure I can do
from Library."file" import "function"
which always work
However, when I started to organise all the notebook in a folder like this
/Main Folder
/Library
some.py
/Notebook
some.ipynb
And the same import
wouldn’t work and return an error Module not found: Library
So I use copilot for help which give me this snippet
import sys
# Get the path to the 'library' folder
library_path = os.path.abspath(os.path.join(os.getcwd(), '..', 'library'))
# Append the 'library' folder to sys.path
if library_path not in sys.path:
sys.path.append(library_path)
Now, when I have this, if I use the same import
as mentioned, it still wouldn’t work, however if I use from "file" import "function"
it works just fines, which I said okay, no worries.
All of that was in Vs code. On Pycharm however I do not need to do any of them, when I use the fix that work on VsCode, Pycharm failed. So I thought there was definitely something wrong with the way the path is reach when the code cell run in Notebook
On a normal python files however, I can simply do “`sys.path.append(os.path.abspath”.”) and no matter the sub-folder, I can reach the code without error.
Any help would be appreciated. Thanks