1

I have a python library in a folder which is not recognised by Anaconda Jupyter Notebook, so if I import <module name> I get No module named '<module name>'.

How can I add the folder to the path? Spyder has the pythonpath manager in which I can just add a folder, but I cannot see how to do it in Jupyter Notebook.

Followup question: is there a way to add a folder to the python path, such that all Anaconda applications, Spyder, Jupyter, etc., recognise it? Or dies it have to be done for each application separately?

2 Answers 2

2

Try appending the path via sys.path.append(path). Docs can be found here.

EDIT: Another option would be to install your package in editable mode so that it runs from the current location.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Brian Larsen . This works thanks! However it has to be redone for any new Notebook I create. I was wondering if there was a way that Jupyter notices those packages by default, without me having to enter that line every time.
@Britzel, I edited the answer to also suggest installing in editable mode.
1

PYTHONPATH is an environment variable that you can set to add additional directories where python will look for modules and packages. The how to depends on your OS. In Windows just search for environment variables.

The only reason to set PYTHONPATH is to access directories with custom libraries that you do not want to install in the default location, i.e. the site-packages directory.

2 Comments

Hi @Peter ! So far I think I understood it. I guess I could try to copy the library into the site-packages folder. But I am still curious how to add another directory to the path in Anaconda Jupyter. As said, I know how to do it in Spyder, but that doesn't effect the Jupyter notebooks.
There is nothing like a path in Anaconda Jupyter or Spyder, there is only the Python sys.path and PYTHONPATH and site-packages are a part of it. You can tweak and hack the sys.path, but this only works on a beginner level. The proper way to access your packages is to conda install (Anaconda) or pip install them and to let these package managers take care of all dependencies too. To install a local package in the Anaconda ecosystem you would use conda develop path/to/your/directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.