目录
1 Jupyter修改默认目录
在cmd中使用如下命令找到配置文件目录:
(base) C:\Users\lenovo>jupyter-notebook --generate-config
Writing default config to: C:\Users\lenovo\.jupyter\jupyter_notebook_config.py
我们通过编辑器,搜索directory定位到如下位置:
## The directory to use for notebooks and kernels.
#c.NotebookApp.notebook_dir = ''
这句话就是设置jupyter的目录的,可见默认值是没有的,我们现在比如要使它指定到我们自己的目录,比如我要让它指定到F盘中的myjupyter文件夹,则修改如下:
## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = 'F:\myjupyter'
保存修改的文件并关闭!然后再打开,发现如下信息,从下面的信息可以看见这样一句话:
Serving notebooks from local directory: F:\myjupyter
这就说明修改成功
完整信息显示如下:
(base) C:\Users\lenovo>jupyter-notebook
[I 14:17:57.432 NotebookApp] JupyterLab beta preview extension loaded from D:\ProgramData\Anaconda3\lib\site-packages\jupyterlab
[I 14:17:57.432 NotebookApp] JupyterLab application directory is D:\ProgramData\Anaconda3\share\jupyter\lab
[I 14:18:00.231 NotebookApp] Serving notebooks from local directory: F:\myjupyter
[I 14:18:00.232 NotebookApp] 0 active kernels
[I 14:18:00.232 NotebookApp] The Jupyter Notebook is running at:
[I 14:18:00.232 NotebookApp] http://localhost:8888/?token=ad2aa0097b0687bbd8b5b11909101533630e781e7c28753b
[I 14:18:00.232 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:18:00.234 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=ad2aa0097b0687bbd8b5b11909101533630e781e7c28753b&token=ad2aa0097b0687bbd8b5b11909101533630e781e7c28753b
[I 14:18:00.786 NotebookApp] Accepting one-time-token-authenticated connection from ::1
注意事项:
第一、文件夹必须先创建好,比如这里F盘下面的myjupyter文件夹要先创建好;不然会jupyter初始化时会找不到目录
第二、要取消注释,c前面的#要去掉
第三、要注意文件名不可以是数字
第四、推荐全部使用anaconda自带的Anaconda Promp进行操作,因为它提供了非常好的环境管理功能
2 Jupyter运行环境的配置
方法一
第一步:激活某一个环境activate mxnet
第二步:在环境中安装ipykernel:pip install ipykernel
第三步:再执行命令:python -m ipykernel install --user --name mxnet --display-name mymxnet
后面的蓝色部分可以省略。第一个mxnet指的是我激活的那一个环境名,这里是mxnet;第二个mymxnet是我要在jupyter里面显示的内核名称,是自己自定义的,我定义为mymxnet
方法二——一步到位的方法
在我创建完我需要的运行环境之后,然后只需要在base运行环境中执行一个命令即可
# 二选一
(base) C:\Users\lenovo>conda install nb_conda
(base) C:\Users\lenovo>conda install nb_conda_kernels
将会将所有的kernel全部添加进去,这种方法是最快的,而且最不容易出错,推荐使用
3 Jupyter常用快捷键
Esc: quit
Enter: edit
Ctrl+Enter: run selected cells
Esc-Y: change cell to code
Esc-M: change cell to markdown
Esc-R: change cell to raw
Esc-A: insert cell above
Esc-B: insert cell below
Esc-D+D: delete selected cells
Esc-X: cut selected cells
Esc-C: copy selected cells
Esc-Shift+V: paste cells above
Esc-V: paste cells below
Shift+M: merge selected cells
Ctrl+Shift+-: split cell at cursor