jupyter notebook修改文件保存位置
时间: 2023-09-03 16:08:25 浏览: 297
默认情况下,Jupyter Notebook的文件保存在启动notebook的目录下。如果你想将文件保存到其他目录,可以通过以下步骤进行修改:
1. 打开Jupyter Notebook并创建一个新的notebook。
2. 在notebook中输入以下代码并执行:
```python
import os
os.chdir('your/file/path')
```
3. 将"your/file/path"替换为你想要保存notebook的目录路径。
4. 接下来,你可以通过文件->保存命令或快捷键(Ctrl + S / Cmd + S)将notebook保存到指定的目录中。
相关问题
修改 Jupyter Notebook 默认文件保存路径
### 修改 Jupyter Notebook 默认文件保存路径
#### 查找当前默认保存路径
通常情况下,Jupyter Notebook 安装完成后,默认的文件保存位置位于用户的主目录下的 `jupyter` 文件夹内[^4]。
#### 创建自定义保存路径
为了指定新的保存路径,首先需要创建一个新的文件夹用于存储 Jupyter Notebook 文件。例如,在 E 盘根目录下建立名为 `python/my_jupyternotebook_file` 的文件夹作为新的工作空间。
#### 配置文件操作
如果 `.jupyter` 文件夹中不存在 `jupyter_notebook_config.py` 这个配置文件,则需通过命令行工具 CMD 来生成该文件。具体做法是在 CMD 中输入以下指令:
```bash
jupyter notebook --generate-config
```
这一步骤会在 C:\Users\<用户名>\.jupyter 下生成所需的配置文件[^5]。
#### 编辑配置文件
找到并打开刚才提到的 `jupyter_notebook_config.py` 文件,定位至其中关于 `c.NotebookApp.notebook_dir` 设置的部分。将此参数设置为你想要使用的绝对路径字符串形式,比如 `'E:\\python\\my_jupyternotebook_file'` (注意使用双反斜杠来转义)。
#### 应用更改
完成上述编辑后保存文件,并重新启动 Jupyter Notebook 服务。此时再访问 Jupyter Notebook Web 界面时,应该能够看到所有新建或上传的笔记本都自动放置到了之前设定的新位置中[^2]。
jupyter notebook的文件保存路径
### Jupyter Notebook 文件默认保存路径
Jupyter Notebook 的默认工作目录通常是启动 Jupyter Notebook 服务所在的文件夹位置。当通过命令行启动 Jupyter Notebook 而未指定其他参数时,默认情况下会在当前的工作目录下运行[^1]。
为了找到确切的默认配置文件以及其设定的默认保存路径,可以执行如下操作:
#### 查看并生成配置文件
可以通过下面这条指令来创建一个新的配置文件(如果之前不存在的话),这一步骤对于查看和调整各种设置非常有用:
```bash
jupyter notebook --generate-config
```
该命令会生成位于用户主目录下的 `.jupyter` 文件夹中的 `jupyter_notebook_config.py` 配置文件[^3]。
#### 定位默认保存路径
在大多数安装环境中,如果没有特别修改过配置项,则 Jupyter Notebook 将使用启动它的终端所在的位置作为根目录。这意味着如果你是在某个特定项目文件夹内开启的服务,那么这个项目的文件夹就会成为新的笔记本文件(.ipynb)被创建时所处的基础位置[^4]。
若要永久改变这一行为,可以在上述提到的配置文件里寻找名为 `c.NotebookApp.notebook_dir` 的选项,并将其指向期望的新路径。例如:
```python
c.NotebookApp.notebook_dir = '/path/to/your/new/default/directory'
```
这样每次启动 Jupyter Notebook 后都会自动进入此自定义路径中[^2]。
阅读全文
相关推荐
















