简体   繁体   中英

How to add folder to PYTHONPATH in Anaconda Jupyter Notebook?

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?

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, ie the site-packages directory.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM