马春杰杰 Exit Reader Mode

[mcj]Conda安装后Jupyter Notebook如何更改默认工作目录

安装完anaconda之后,一般默认会安装Jupyter Notebook,一般在终端输入jupyter notebook即可打开。

C:\Users\mcj>conda activate qoe

(qoe) C:\Users\mcj>jupyter notebook
[I 15:10:02.356 NotebookApp] Writing notebook server cookie secret to C:\Users\mcj\AppData\Roaming\jupyter\runtime\notebook_cookie_secret
[I 15:10:04.688 NotebookApp] JupyterLab beta preview extension loaded from E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab
[I 15:10:04.688 NotebookApp] JupyterLab application directory is E:\ProgramData\Anaconda3\share\jupyter\lab
[I 15:10:05.237 NotebookApp] Serving notebooks from local directory: C:\Users\mcj
[I 15:10:05.237 NotebookApp] 0 active kernels
[I 15:10:05.237 NotebookApp] The Jupyter Notebook is running at:
[I 15:10:05.237 NotebookApp] https://localhost:8888/?token=94bb0ee83f45a13246d69c032f3c9999fcc89c49f54f0d85
[I 15:10:05.237 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:10:05.237 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        https://localhost:8888/?token=94bb0ee83f45a13246d69c032f3c9999fcc89c49f54f0d85&token=94bb0ee83f45a13246d69c032f3c9999fcc89c49f54f0d85
[I 15:10:05.646 NotebookApp] Accepting one-time-token-authenticated connection from ::1

这样打开的jupyter notebook一般是在当前目录下,如上面就是在c:\Users\mcj\下,这时如果想要修改为自定义的路径,可以先在命令行下进入目录,然后打开notebook,不过这样未免有些麻烦,还有一种方法是直接在后面加上路径名,如:

(qoe) C:\Users\mcj>jupyter notebook  d:
[I 15:13:54.304 NotebookApp] JupyterLab beta preview extension loaded from E:\ProgramData\Anaconda3\lib\site-packages\jupyterlab
[I 15:13:54.304 NotebookApp] JupyterLab application directory is E:\ProgramData\Anaconda3\share\jupyter\lab
[I 15:13:54.723 NotebookApp] Serving notebooks from local directory: D:\
[I 15:13:54.723 NotebookApp] 0 active kernels
[I 15:13:54.723 NotebookApp] The Jupyter Notebook is running at:
[I 15:13:54.723 NotebookApp] https://localhost:8888/?token=39ca8bd99b215a054252b09d2a96ee52f71389ba2f082d21
[I 15:13:54.723 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:13:54.723 NotebookApp]

    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        https://localhost:8888/?token=39ca8bd99b215a054252b09d2a96ee52f71389ba2f082d21&token=39ca8bd99b215a054252b09d2a96ee52f71389ba2f082d21
[I 15:13:54.983 NotebookApp] Accepting one-time-token-authenticated connection from ::1

这样打开的就是在D盘下了:

当然,这种方法有时候也挺麻烦的,这时,就可以通过修改notebook配置文件来永久修改了,方法如下:

首先查看一下Jupyter Notebook的配置文件位置:

jupyter notebook --generate-config//会生成文件C:\Users\用户\.jupyter\jupyter_notebook_config.py

然后打开生成的文件jupyter_notebook_config.py,搜索c.NotebookApp.notebook_dir,这就是默认的路径了。我们把它修改为自定义的路径:

c.NotebookApp.notebook_dir = 'E:\\tf_models'     //修改到自定义文件夹

最后重启一下服务器即可