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

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


当前回答

要在OS X中的Windows上执行下面描述的相同技巧,请创建这个shell脚本

#!/bin/bash
cd $(dirname "$0") && pwd
ipython notebook

将其命名为ipython-notebook.command并使其可执行。

把它放到你想要工作的目录中,然后双击它。

其他回答

对于Mac OS X,目标目录中有空格(后续使用@pheon)。在第2行$(…)周围添加额外的双引号。参见:https://stackoverflow.com/a/1308838(肖恩·布莱特)

#!/bin/bash
cd "$(dirname "$0")" && pwd
ipython notebook

我有32位和64位的python和使用WinPython的ipython,我想要32位和64位的版本指向ipython笔记本的相同工作目录。

我按照上面的建议在这里,我仍然无法让我的设置工作。

以下是我所做的——以防有人需要:


看起来Ipython notebook使用了来自C:\pythonPath\winpythonPath\settings\.ipython\profile_default的配置

尽管ipython locate返回C:\users\Username\.ipython

因此,修改ipython_notebook_config.py文件并没有改变我的工作目录。

另外,ipython profile_create没有在C:\pythonPath\winpythonPath\settings\.ipython\profile_default中创建所需的python文件

我相信有更好的方法,但为了快速解决这个问题,我从C:\users\Username\复制了编辑好的python文件。C:\pythonPath\winpythonPath\settings\.ipython\profile_default

现在(终于)ipython notebook 64位运行并为我提供正确的工作目录

注意在Windows上,我对以下语法没有问题:

c.NotebookApp.notebook_dir = u'C:/Users/Path_to_working_directory'

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将是您的默认启动位置。)

当从命令行启动时,IPython Notebook将使用您的当前工作目录。我利用了这一点,创建了上下文菜单项,直接从Windows资源管理器打开它。不需要快捷方式或批处理脚本!

我的灵感来自于Git for Windows创建的基于注册表的“Git GUI Here/Git Bash Here”条目。这个页面(链接了存档版本)有助于定位正确的键。

第一对是没有任何选择的上下文菜单(例如目录背景)。笔记本将以当前目录作为工作目录打开。

Key: HKCR\Directory\Background\shell\ipythonnb
Value: &IPython Notebook Here

Key: HKCR\Directory\Background\shell\ipythonnb\command
Value: "<full path to IPython notebook>" "%v"

这一对用于单击文件夹时显示的上下文菜单。笔记本将以所选文件夹作为工作目录打开。

Key: HKCR\Directory\shell\ipythonnb
Value: &IPython Notebook Here

Key: HKCR\Directory\shell\ipythonnb\command
Value: "<full path to IPython notebook>" "%1"

注意%v vs %1参数,否则它将不起作用。也不要忘记引用。在我的平台上,IPython Notebook的完整路径是C:\WinPython-32bit-2.7.6.4\IPython Notebook.exe,但这个值显然取决于您的安装。

编辑:AFAICT完整路径是必需的,即使可执行文件在系统路径上。

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.