6

我的文件夹结构如下所示:

- project/
  - notebooks/
    - notebook1.ipynb
  - src/
    - module1.py
    - __init__.py
  - data/
    - data.csv

这样我就可以将我的源代码与实际分析分开。我希望能够从中导入模块src并在其中使用它们notebook1,但是每当我打开时notebook1,Jupyter 都会决定将我的工作目录更改为里面notebooks

这使得我的导入更难维护,因为我必须导入相对于 Jupyter 的突发奇想的东西 - 有没有什么办法可以修复它,无论我打开什么文件cwd,它总是如此?project

我查看了文档和我的~/.jupyter/jupyter_notebook_config.py, 文件,但没有发现任何可以帮助我的东西。

编辑:我不想在每个脚本的顶部使用os.chdir或。cd

谢谢你的帮助

4

1 回答 1

0

First of all, I think you mean cwd, pwd is the shorthand for print working directory, whereas cwd is the shorthand for current working directory. Essentially, the pwd prints the cwd. Just a minor terminology issue there!

Secondly, you could always manually change the directory yourself at the top of the notebook:

import os
os.chdir("../")  # or manually specify project - whichever you prefer

I don't think there's any way to change the default behaviour automatically though - perhaps opening an issue on the notebook git repo would be a good idea? https://github.com/jupyter/notebook

于 2017-03-27T16:04:26.873 回答