简体   繁体   English

Pycharm Jupyter笔记本`PYTHONPATH`?

[英]Pycharm Jupyter Notebook `PYTHONPATH`?

System information 系统信息

  • Mac OS X 10.12 Sierra Mac OS X 10.12 Sierra
  • Pycharm 2016.2.3 皮查姆2016.2.3
  • Python 3.5.1 的Python 3.5.1
  • Jupyter 4.1.0 Jupyter 4.1.0

Question

When I'm using Jupyter Notebook under Pycharm, it doesn't seem to include my current working directory, or the source root directory, in the PYTHONPATH of the currently active Jupyter Notebook. 当我在Pycharm下使用Jupyter Notebook时,它似乎没有在当前活动的Jupyter Notebook的PYTHONPATH中包含我的当前工作目录或源根目录。 This is unlike the behaviour of ordinary .py files, for which Pycharm automatically includes its current directory and the project source root directory in the PYTHONPATH . 这与普通.py文件的行为不同,Pycharm为此自动将其当前目录和项目源根目录包括在PYTHONPATH So, is it possible to set Pycharm to automatically include the project source root directory in the PYTHONPATH for Jupyter Notebooks run under Pycharm? 因此,是否可以将Pycharm设置为在Pycharm下运行的Jupyter Notebook的PYTHONPATH自动包含项目源根目录?

Pycharm 2019.1 has done an overhaul of Jupyter support. Pycharm 2019.1已完成Jupyter支持的全面检查。 Jetbrains says this in reference to Pycharm 2019.1: "Jupyter Notebook support in PyCharm was redesigned from the ground up." Jetbrains提到Pycharm 2019.1时这样说:“从头开始重新设计了PyCharm中的Jupyter Notebook支持。”

So, as of Pycharm 2019.1, you can now set Pycharm to include the project source root directory for Jupyter Notebooks. 因此,从Pycharm 2019.1开始,您现在可以将Pycharm设置为包括Jupyter Notebooks的项目源根目录。

See this page of Pycharm 2019.1 help. 请参阅Pycharm 2019.1帮助的此页面

There's a bunch of ways to mess with the environment, but the PyCharm specific way that worked for me was to make the directory with my source in it a PyCharm "sources root" as described here: https://www.jetbrains.com/help/pycharm/content-root.html 有很多方法可以破坏环境,但是对我有用的PyCharm特定方法是使其中包含我的源的目录成为PyCharm的“源根目录”,如下所述: https : //www.jetbrains.com/ help / pycharm / content-root.html

This can be done from the context menu of a directory in the navigator, or from the "Project Structure" settings pane. 可以从导航器中目录的上下文菜单或“项目结构”设置窗格中完成此操作。

This seems to update the PYTHONPATH as well as sorting out things like autocomplete. 这似乎更新了PYTHONPATH并整理了诸如自动完成之类的内容。

It turns out, in a past endeavour, I modified my jupyter_notebook_config.py in %USER%\\.jupyter folder. 事实证明,在过去的努力,我修改了jupyter_notebook_config.py%USER%\\.jupyter文件夹中。 Looked at lines as follows: 看行如下:

## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'D:\\Works\\GitHub\\Jupyter\\'

The line under the ## , indicates the override path, evidently. 显然, ##下的线表示替代路径。

When I commented it out...Pycharm all of the sudden successfully launched with pwd of the file (location of the .ipynb). 当我将其注释掉... Pycharm突然用文件的pwd(.ipynb的位置)成功启动。 good luck, hth. 祝你好运。

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

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