当我打开Jupyter笔记本(以前是IPython)时,它默认为c:\ users \ username

我如何将其更改为另一个位置?


当前回答

正如MrFancypants在评论中提到的,如果你正在使用Jupyter(你应该这样做,因为它目前取代了旧的IPython Notebook项目),事情就有点不同了。首先,已经没有档案了。

安装Jupyter后,首先检查~/。Jupyter文件夹查看其内容。如果没有配置文件从默认的IPython配置文件迁移(在我的情况下没有),为Jupyter Notebook创建一个新的配置文件:

jupyter notebook --generate-config

这会生成~/.jupyter/jupyter_notebook_config.py文件,其中包含一些有用的注释可能的选项。设置默认目录add。

c.NotebookApp.notebook_dir = u'/absolute/path/to/notebook/directory'

当我在Linux和OS X之间切换时,我想使用一个相对于我的主文件夹的路径(因为它们不同- /Users/username和/home/username),所以我设置了如下内容:

import os
c.NotebookApp.notebook_dir = os.path.expanduser('~/Dropbox/dev/notebook')

现在,每当我运行jupyter笔记本,它打开我想要的笔记本文件夹。我还对整个~/进行了版本化。jupyter文件夹在我的dotfiles存储库,我部署到每一个新的工作机器。


顺便说一句,您仍然可以使用——notebook-dir命令行选项,因此可能一个简单的别名更适合您的需要。

jupyter notebook --notebook-dir=/absolute/path/to/notebook/directory

其他回答

通常$ ipython notebook将在终端的当前工作目录下启动笔记本和内核。

但是如果你想指定启动目录,你可以使用——notebook-dir选项,如下所示:

$ ipython notebook——notebook-dir=/path/to/specific/directory

This might help someone who doesn't want to change config file. If you are on Windows/ using Anaconda3, go to Win Start ->Search for Jupyter Notebook(env). Click on it and the Jupyter opens up. On Jupyter webpage, on right hand side go to New -> Terminal and the terminal window opens up. In this terminal windows change the directory to the working directory, using cd command. Example: cd "c:\User\<user-name>\workingdir". Now in the same terminal window type Jupyter-notebook, this will open Jupyter with the working directory we used in cd command above.

试试nbopen模块。当你安装并将其与windows资源管理器集成在一起时,你将能够通过双击打开任何笔记本电脑。

我将在这里补充一长串的答案。如果您在Windows上/使用Anaconda3,我通过转到文件/Scripts/ipython-script.py完成了这一点,并添加了这些行

import os
os.chdir(<path to desired dir>)

排队前

sys.exit(IPython.start_ipython())

Jupyter笔记本——help-all可能会有帮助:

--notebook-dir=<Unicode> (NotebookManager.notebook_dir)
    Default: u'/Users/me/ipynbs'
    The directory to use for notebooks.

例如:

jupyter notebook --notebook-dir=/Users/yourname/folder1/folder2/

如果需要,你当然可以在你的配置文件中设置它,你可能需要在Windows中转义反斜杠。

注意,这将覆盖您在jupyter_notebook_config.py文件中设置的任何路径。(在这里你可以设置一个变量c.NotebookApp。Notebook_dir将是您的默认启动位置。)