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

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


当前回答

如果你在windows中使用ipython,那么按照以下步骤:

在程序中导航到ipython notebook,并右键单击它和 进入属性。 在快捷选项卡中,将“开始”目录更改为您所需的目录 目录中。 重新启动内核。

其他回答

当我搜索ipython change pwd时,这个问题不断出现,尽管我对笔记本电脑不感兴趣,但我对终端或qtconsole感兴趣。没有找到相关的配置项,我尝试了:

# lines of code to run at IPython startup.
c.InteractiveShellApp.exec_lines = ['%cd /home/paul/mypy']

这是基本的shell类;还有终端和控制台(可能还有笔记本)条目可以进一步定制操作。

从文档来看,import语句在条目中最常见,但似乎许多神奇的命令也能起作用。

在命令行输入“jupyter notebook”之前导航到所需的文件夹。

在我的情况下,我所有的python文件都在“D:\ python”。

然后输入命令“jupyter notebook”,你就有了它。您已经更改了工作目录。

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.

我有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'

正如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