简体   繁体   English

如何在 Anaconda Jupyter Notebook 中将文件夹添加到 PYTHONPATH?

[英]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>' .我在 Anaconda Jupyter Notebook 无法识别的文件夹中有一个 python 库,所以如果我import <module name>我得到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. Spyder 有 pythonpath 管理器,我可以在其中添加一个文件夹,但在 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?后续问题:有没有办法在python路径中添加一个文件夹,让所有的Anaconda应用程序,Spyder,Jupyter等都能识别? 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. PYTHONPATH 是一个环境变量,你可以设置它来添加额外的目录,python 将在其中查找模块和包。 The how to depends on your OS. how to取决于您的操作系统。 In Windows just search for environment variables .在 Windows 中只需搜索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.设置 PYTHONPATH 的唯一原因是访问包含您不想安装在默认位置(即site-packages目录)中的自定义库的目录。

Try appending the path via sys.path.append(path) .尝试通过sys.path.append(path)附加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.编辑:另一种选择是以可编辑模式安装您的包,以便它从当前位置运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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