IPython Notebook 保存位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18901185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IPython Notebook save location
提问by Yuxiang Wang
I just started IPython Notebook, and I tried to use "Save" to save my progress. However, instead of saving the *.ipynb in my current working directory, it is saved in my python/Scripts folder. Would there be a way to set this?
我刚刚启动了 IPython Notebook,我尝试使用“保存”来保存我的进度。但是,它不是将 *.ipynb 保存在我当前的工作目录中,而是保存在我的 python/Scripts 文件夹中。有没有办法设置这个?
Thanks!
谢谢!
采纳答案by Viktor Kerkez
Yes, you can specify the notebooks location in your profile configuration. Since it's not saving them to the directory where you started the notebook, I assume that you have this option set in your profile. You can find out the the path to the profiles directory by using:
是的,您可以在配置文件配置中指定笔记本位置。由于它没有将它们保存到您启动笔记本的目录中,因此我假设您在配置文件中设置了此选项。您可以使用以下命令找出配置文件目录的路径:
$ ipython locate
Either in your default profile or in the profile you use, edit the ipython_notebook_config.py
file and change the lines:
在您的默认配置文件或您使用的配置文件中,编辑ipython_notebook_config.py
文件并更改行:
Note: In case you don't have a profile, or the profile folder does not contain the ipython_notebook_config.py
file, use ipython profile create
.
注意:如果您没有配置文件,或者配置文件文件夹不包含该ipython_notebook_config.py
文件,请使用ipython profile create
.
# The directory to use for notebooks.
c.NotebookManager.notebook_dir = u'/path/to/your/notebooks'
and
和
# The directory to use for notebooks.
c.FileNotebookManager.notebook_dir = u'/path/to/your/notebooks'
Or just comment them out if you want the notebooks saved in the current directory.
或者,如果您希望将笔记本保存在当前目录中,只需将它们注释掉。
Update (April 11th 2014):in IPython 2.0 the property name in the config file changed, so it's now:
更新(2014 年 4 月 11 日):在 IPython 2.0 中,配置文件中的属性名称已更改,因此现在是:
c.NotebookApp.notebook_dir = u'/path/to/your/notebooks'
回答by user2797779
- Based on my experience, if you use "ipython.exe" in python-2.7.5/Scripts from other directory, as typing at the comamnd prompt as ipython notebook, *.ipynb files will be loaded and saved in the current directory. ("notebook" is just a comamnd line parameter) I think the "ipython notebook.exe" in Winpython top directory is not relevant for your request. As for me, I added the ipython.exe directory to the Path only.
- If you want to make your profile in user directory, see below: https://code.google.com/p/winpython/wiki/Installation#Settings
- 根据我的经验,如果您在其他目录的 python-2.7.5/Scripts 中使用“ipython.exe”,在 comamnd 提示符下输入ipython notebook,*.ipynb 文件将被加载并保存在当前目录中。(“notebook”只是一个命令行参数)我认为 Winpython 顶级目录中的“ipython notebook.exe”与您的请求无关。至于我,我只将 ipython.exe 目录添加到 Path 中。
- 如果您想在用户目录中创建您的个人资料,请参见以下内容:https: //code.google.com/p/winpython/wiki/Installation#Settings
回答by nagordon
To run in Windows, copy this *.bat file to each directory you wish to use and run the ipython notebook by executing the batch file. This assumes you have ipython installed in windows.
要在 Windows 中运行,请将此 *.bat 文件复制到您希望使用的每个目录中,然后通过执行批处理文件来运行 ipython notebook。这假设您在 Windows 中安装了 ipython。
set "var=%cd%"
cd var
ipython notebook
回答by the_prole
To add to Victor's answer, I was able to change the save directory on Windows using...
为了添加维克多的答案,我能够使用...更改 Windows 上的保存目录。
c.NotebookApp.notebook_dir = 'C:\Users\User\Folder'
回答by Ida
If you're using IPython 4.x/Jupyter, run
如果您使用的是 IPython 4.x/Jupyter,请运行
$ jupyter notebook --generate-config
This will create a file jupyter_notebook_config.py
in ~/.jupyter
. This file already has a line starting with # c.NotebookApp.notebook_dir=u''
.
这将jupyter_notebook_config.py
在~/.jupyter
. 该文件已经有一行以# c.NotebookApp.notebook_dir=u''
.
All you need to do is to uncomment this line and change the value to your desired location, e.g., c.NotebookApp.notebook_dir=u'/home/alice/my_ipython_notebooks'
您需要做的就是取消注释此行并将值更改为您想要的位置,例如, c.NotebookApp.notebook_dir=u'/home/alice/my_ipython_notebooks'
回答by Pradi KL
Just cd
to your working folder and then start the IPython notebook server
. This way you can be mobile.
只需cd
到您的工作文件夹,然后启动IPython notebook server
. 这样你就可以移动了。
回答by Muhamed Al Khalil
Jupyter under the WinPythonenvironment has a batch file in the scripts
folder called:
WinPython环境下的jupyter在scripts
文件夹中有一个批处理文件,名为:
make_working_directory_be_not_winpython.bat
You need to edit the following line in it:
您需要在其中编辑以下行:
echo WINPYWORKDIR = %%HOMEDRIVE%%%%HOMEPATH%%\Documents\WinPython%%WINPYVER%%\Notebooks>>"%winpython_ini%"
replacing the Documents\WinPython%%WINPYVER%%\Notebooks
part with your folder address.
用Documents\WinPython%%WINPYVER%%\Notebooks
您的文件夹地址替换该部分。
Notice that the %%HOMEDRIVE%%%%HOMEPATH%%\
part will identify the root and user folders (i.e. C:\Users\your_name\
) which will allow you to point different WinPython installations on separate computers to the same cloud storage folder (e.g. OneDrive) where you could store, access, and work with the same files from different machines. I find that very useful.
请注意,该%%HOMEDRIVE%%%%HOMEPATH%%\
部分将识别根和用户文件夹(即C:\Users\your_name\
),这将让你点在不同的电脑不同的WinPython安装到同一个云存储文件夹(如OneDrive),在那里你可以存储,访问和工作,从相同的文件不同的机器。我觉得这很有用。
回答by HashRocketSyntax
I tried the other solutions, but I didn't find that c.NotebookApp.notebook_dir
setting in the config...
我尝试了其他解决方案,但我没有c.NotebookApp.notebook_dir
在配置中找到该设置...
#jupyter_notebook_config.json
{
"NotebookApp": {
"nbserver_extensions": {
"jupyter_nbextensions_configurator": true
}
}
}
So, what I do is:
所以,我要做的是:
cd
into the directory where I want the notebooks and checkpoints saved- start the notebook server
jupyter-lab
- then, in an active notebook cell, I change my working directory so that the code in my python cells can access my other modules =)
cd
进入我想要保存笔记本和检查点的目录- 启动笔记本服务器
jupyter-lab
- 然后,在活动笔记本单元中,我更改我的工作目录,以便我的 python 单元中的代码可以访问我的其他模块 =)
# ipython cell
import os
# change where notebooks are stored
os.chdir('/Users/me/Project')
os.getcwd()