当我打开Jupyter笔记本(以前是IPython)时,它默认为c:\ users \ username
我如何将其更改为另一个位置?
当我打开Jupyter笔记本(以前是IPython)时,它默认为c:\ users \ username
我如何将其更改为另一个位置?
当前回答
只需遵循官方网站上的指南,也复制在下面。对于第一步,而不是复制启动器,您只需转到开始菜单并右键单击打开位置。
Copy the Jupyter Notebook launcher from the menu to the desktop. Right click on the new launcher and change the “Start in” field by pasting the full path of the folder which will contain all the notebooks. Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start the Jupyter Notebook App, which will open in a new browser window (or tab). Note also that a secondary terminal window (used only for error logging and for shut down) will be also opened. If only the terminal starts, try opening this address with your browser: http://localhost:8888/.
其他回答
当从命令行启动时,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完整路径是必需的,即使可执行文件在系统路径上。
通常$ ipython notebook将在终端的当前工作目录下启动笔记本和内核。
但是如果你想指定启动目录,你可以使用——notebook-dir选项,如下所示:
$ ipython notebook——notebook-dir=/path/to/specific/directory
我将在这里补充一长串的答案。如果您在Windows上/使用Anaconda3,我通过转到文件/Scripts/ipython-script.py完成了这一点,并添加了这些行
import os
os.chdir(<path to desired dir>)
排队前
sys.exit(IPython.start_ipython())
%pwd #look at the current work dir
%cd #change to the dir you want
对于那些在windows中使用IPython的人来说,一个巧妙的技巧是,可以在每个项目目录中创建一个IPython图标,以笔记本指向所选的项目打开。这有助于把事情分开。
例如,如果你在C:\fake\example\目录下有一个新项目
复制一个ipython notebook图标到目录中,或者创建一个到windows“cmd”shell的新链接。然后右键点击图标,选择“编辑属性”
设置快捷方式属性为:
Target:
C:\Windows\System32\cmd.exe /k "cd C:\fake\example\directory & C: & ipython notebook --pylab inline"
Start in:
C:\fake\example\directory\
(注意“start in”后面加了斜杠)
这将运行windows命令行,更改您的工作目录,并运行指向该目录的ipython notebook。
在每个项目文件夹中放入一个这样的文件夹,你就会有一个ipython笔记本组,保持良好和独立,同时仍然只需要双击。
更新:IPython已经删除了对pylab的命令行内联的支持,所以如果你有一个更新的IPython版本(或者只是不想要pylab),这个诀窍的修复方法就是消除“——pylab inline”。
更新JUPYTER笔记本~版本4.1.1
在我的测试机器上,正如下面评论中报告的那样,最新的jupyter构建似乎检查了开始目录,并将其作为工作目录启动。这意味着不需要重写工作目录。
因此,你的快捷方式可以像这样简单:
Target (if jupyter notebook in path):
jupyter notebook
Target (if jupyter notebook NOT in path):
C:\Users\<Your Username Here>\Anaconda\Scripts\jupyter.exe notebook
如果jupyter notebook不在你的PATH中,你只需要在命令前添加完整的目录引用。如果这不能工作,请尝试从早期版本工作。非常方便的是,现在“Start in:”可以在4.1.1及以后版本的测试中为空。也许他们读了这篇关于SO的文章,喜欢它,这么长时间的赞,没有人再需要它了:)