更改IPython/Jupyter笔记本工作目录

更改IPython/Jupyter笔记本工作目录,ipython,jupyter-notebook,jupyter,Ipython,Jupyter Notebook,Jupyter,当我打开Jupyter笔记本(以前是IPython)时,它默认为C:\Users\USERNAME 我如何才能将其更改到其他位置?jupyter笔记本--帮助所有人都可以提供帮助: --notebook-dir=<Unicode> (NotebookManager.notebook_dir) Default: u'/Users/me/ipynbs' The directory to use for notebooks. 当然,如果需要,您可以在配置文件中设置它,您可

当我打开Jupyter笔记本(以前是IPython)时,它默认为
C:\Users\USERNAME

我如何才能将其更改到其他位置?

jupyter笔记本--帮助所有人
都可以提供帮助:

--notebook-dir=<Unicode> (NotebookManager.notebook_dir)
    Default: u'/Users/me/ipynbs'
    The directory to use for notebooks.
当然,如果需要,您可以在配置文件中设置它,您可能需要在Windows中转义反斜杠


请注意,这将覆盖您可能在jupyter\u notebook\u config.py文件中设置的任何路径。(您可以在其中设置变量
c.NotebookApp.notebook_dir
,该变量将作为默认启动位置。)

对于在windows中使用IPython的人来说,一个巧妙的技巧是,您可以在每个项目目录中创建一个IPython图标,设计为打开时笔记本指向所选项目。这有助于将事情分开

例如,如果您在C:\fake\example\directory中有一个新项目

将ipython笔记本图标复制到目录或创建指向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\
(注意在“起始位置”末尾添加的斜杠)

这将运行windows命令行,更改您的工作目录,并运行指向该目录的ipython笔记本

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"
在每个项目文件夹中放一个这样的文件夹,你就可以让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笔记本在路径中):
jupyter笔记本
目标(如果jupyter笔记本不在路径中):
C:\Users\\Anaconda\Scripts\jupyter.exe笔记本

如果jupyter笔记本不在您的路径中,您只需要在命令前面添加完整的目录引用。如果不起作用,请尝试使用早期版本。非常方便的是,现在在4.1.1及更高版本的测试中,“Start in:”可以为空。也许他们是在某某网站上读到这篇文章并喜欢它,这么久了,没有人再需要它了:)

在Windows上的iPython笔记本中,这对我很有用:

cd d:\folder\

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

#!/bin/bash
cd $(dirname "$0") && pwd
ipython notebook
#!/bin/bash
cd "$(dirname "$0")" && pwd
ipython notebook
将其命名为ipython-notebook.command并使其可执行


将它放在您要使用的目录中,然后双击它

除了@Matt的方法外,永久更改笔记本电脑默认目录的一种方法是更改配置文件。首先,在cmdline中键入:

$> ipython profile create
使用默认配置文件初始化配置文件。其次,在文件
ipython\u notebook\u config.py
中,取消注释并编辑此行:

# c.NotebookManager.notebook_dir = 'D:\\Documents\\Desktop'
D:\\Documents\\Desktop
更改为您喜欢的任何路径

这对我有用;)

更新:不再有
c.NotebookManager.notebook\u dir
。 现在,取消注释和配置的行是:
c.NotebookApp.notebook\u dir='Z:\\username\u example\folder\u that\u you\u what'

对上述Windows技巧的简单修改-无需硬编码目录

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"
A) 创建包含以下内容的批处理文件: (注意:批处理文件是一个简单的文本文件,其中包含可以 必须在cmd窗口中运行。它必须具有“.bat”扩展名,因此。。。 您需要禁用隐藏已知类型扩展名的文件夹设置)

B) 将批处理文件复制并粘贴到要启动笔记本服务器的任何文件夹中

(确保它是您有权编辑的文件夹。“C:\”不是一个好选择。)

C) 双击Windows资源管理器中的批处理文件


笔记本服务器应正常启动。

从命令行启动时,IPython笔记本将使用您当前的工作目录。我利用这一点,创建了上下文菜单项,直接从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"
Key:HKCR\Directory\Background\shell\ipythonnb
值:&此处为IPython笔记本
关键字:HKCR\Directory\Background\shell\ipythonnb\command
值:“%v”
这一对用于单击文件夹时显示的上下文菜单。笔记本将以所选文件夹作为其工作目录打开

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"
Key:HKCR\Directory\shell\ipythonnb
值:&此处为IPython笔记本
关键字:HKCR\Directory\shell\ipythonnb\command
值:“%1”
请注意
%v
vs
%1
参数,否则它将不起作用。也别忘了引用。在我的平台上,IPython Notebook的完整路径是
C:\WinPython-32bit-2.7.6.4\IPython Notebook.exe
,但该值显然取决于您的安装


编辑:即使可执行文件位于系统路径上,也需要完整路径。

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

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

$ipython notebook--notebook dir=/path/to/specific/directoryDIR=$(dirname $0)
$DIR/ipython notebook --notebook-dir=u'../rel/path/to/your/python-notebooks'
c.NotebookApp.notebook_dir = u'C:/Users/Path_to_working_directory'
jupyter notebook --generate-config
c.NotebookApp.notebook_dir = u'/absolute/path/to/notebook/directory'
import os
c.NotebookApp.notebook_dir = os.path.expanduser('~/Dropbox/dev/notebook')
jupyter notebook --notebook-dir=/absolute/path/to/notebook/directory
# lines of code to run at IPython startup.
c.InteractiveShellApp.exec_lines = ['%cd /home/paul/mypy']
#SingleInstance Force
#NoTrayIcon

SetTitleMatchMode RegEx

; Press CTRL+ALT+I in a Windows Explorer window to launch a IPython notebook server in the current folder.
^+!i::
; Get the current path.
Send ^l
; Backup the current clipboard.
ClipSaved := ClipboardAll
; Copy and save the current path.
Send ^c
ClipWait
x = %Clipboard%
; Restore the clipboard.
Clipboard := ClipSaved
ClipSaved = ; Free the memory in case the clipboard was very large.
; Now, run the IPython notebook server.
RunWait, ipython notebook --notebook-dir "%x%", , min
return

^i::
; Now, run the IPython notebook server.
RunWait, jupyter notebook --notebook-dir "C:\Path\To\Workspace", , min
return

; Press CTRL+ALT+P to kill all Python processes.
^!p::
Run, taskkill /f /im python.exe, , min
return
1. Open file
2. find the line 
3. save and close.
C:\Program Files\Miniconda2\cwp.py
try:
    documents_folder = get_folder_path(FOLDERID.Documents)
    development_folder= 'C:\Users\USERNAME\Development'
except PathNotFoundException:
    documents_folder = get_folder_path(FOLDERID.PublicDocuments)
os.chdir(development_folder)
subprocess.call(args, env=env)
C:\Users\USERNAME>
C:\Users\USERNAME>cd D:\MyProjectFolder
D:\MyProjectFolder>
D:\MyProjectFolder>jupyter notebook
import os
os.chdir(<path to desired dir>)
sys.exit(IPython.start_ipython())
#c.NotebookApp.notebook_dir = '' 
c.NotebookApp.notebook_dir = 'D:/your/desired/path'