I have a Jupyter notebook, I want to use local python functions from other folders in my computer.
When I do import to these functions I get this error:
"ModuleNotFoundError: No module named 'xxxxxxxxxxxxx'
- I'm using anaconda as the python interpreter
You can add a path using sys
to your local module/python file.
import sys
sys.path.append("/path/to/file/") # path contains python_file.pyimport python_file
If you want a more permanent solution by adding module to Anaconda path, see previous answer from cord-kaldemeyer https://stackoverflow.com/a/37008663/7019148. Content copied below for completeness:
I found two answers to my question in the Anaconda forum:
1.) Put the modules into into site-packages, i.e. the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages which is always onsys.path. This should also work by creating a symbolic link.
2.) Add a .pth file to the directory $HOME/path/to/anaconda/lib/pythonX.X/site-packages. This can be namedanything (it just must end with .pth). A .pth file is just anewline-separated listing of the full path-names of directories thatwill be added to your path on Python startup.
Both work straightforward and I went for the second option as it ismore flexible.
*** UPDATE:
3.) Create a setup.py in the folder of your package and install it using pip install -e /path/to/package which is the cleanest optionfrom my point of view because you can also see all installations usingpip list.
Thanks anyway!