当我打开Jupyter笔记本(以前是IPython)时,它默认为c:\ users \ username
我如何将其更改为另一个位置?
当我打开Jupyter笔记本(以前是IPython)时,它默认为c:\ users \ username
我如何将其更改为另一个位置?
当前回答
您还可以使用AutoHotKey与一个简单的脚本打开一个Jupyter笔记本服务器的默认目录(CTRL+I)或在资源管理器高亮显示的路径(或其他地方与CTRL+SHIFT+I)。
#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
其他回答
正如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二进制文件。如果你使用anaconda在mac上安装ipython-notebook,它很可能会在/Users/[name]/anaconda/bin/目录下
在那个目录下,而不是启动你的笔记本
./ipython notebook
添加——notebook-dir=<unicode>选项。
./ipython notebook --notebook-dir=u'../rel/path/to/your/python-notebooks'
我在ipython bin目录中使用bashscript启动我的笔记本:
DIR=$(dirname $0)
$DIR/ipython notebook --notebook-dir=u'../rel/path/to/your/python-notebooks'
注意-到notebook目录的路径是相对于ipython bin目录的。
对于linux和Windows: 只要修改一行,你就可以改变它。
1. Open file
cwp.py
in
C:\Users\[您的计算机名]\Anaconda2
.
2. find the line
os.chdir (documents_folder)
在文件的末尾。
改为
操作系统。Chdir(“您期望的工作文件夹”)
例如:os.chdir("D:/Jupyter_folder")
3. save and close.
它工作。
更新:
说到MacOS,我找不到ccp .py。 以下是我的发现:
打开你的Macbook终端,运行'jupyter notebook -generate-config'。
它将在/Users/[your_username]/.jupyter/jupyter_notebook_config.py目录下创建一个配置文件
打开配置文件,然后更改这一行#c.NotebookApp。Notebook_dir = " 来 c.NotebookApp。Notebook_dir = '你的路径' 记住这一行也要取消注释。
例如,我将路径更改为“/Users/catbuilts/JupyterProjects/”
import sys
sys.path.append('C:/')
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.