jupyter的安装参考:python环境安装jupyter-CSDN博客
1,背景
继上一篇python环境安装jupyter,里面有一个问题,就是启动jupyter(命令jupyter notebook)之后,页面默认显示的是启动时候的路径。
那有没有可能每次启动,让其自动进入项目文件夹呢?
2,配置Jupyter启动路径
在实际配置之前,可以看一下jupyter notebook有那些命令
C:\Users\PC>jupyter notebook --help
Jupyter Notebook - A web-based notebook environment for interactive computingOptions
=======
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:<cmd> --help-all--debugSet debug level for the extension and underlying server applications.Equivalent to: [--ServerApp.log_level=DEBUG --ExtensionApp.log_level=DEBUG]
--show-configShow the application's configuration (human-readable format)Equivalent to: [--Application.show_config=True]
--show-config-jsonShow the application's configuration (json format)Equivalent to: [--Application.show_config_json=True]
--generate-config #生成默认配置文件generate default config fileEquivalent to: [--JupyterApp.generate_config=True]
-yAnswer yes to any questions instead of prompting.Equivalent to: [--JupyterApp.answer_yes=True]
--allow-rootAllow the server to be run from root user.Equivalent to: [--ServerApp.allow_root=True]
--no-browserPrevent the opening of the default url in the browser.Equivalent to: [--ServerApp.open_browser=False --ExtensionApp.open_browser=False]
--autoreloadAutoreload the webappEnable reloading of the tornado webapp and all imported Python packageswhen any changes are made to any Python src files in server orextensions.Equivalent to: [--ServerApp.autoreload=True]
--scriptDEPRECATED, IGNOREDEquivalent to: [--FileContentsManager.save_script=True]
--no-scriptDEPRECATED, IGNOREDEquivalent to: [--FileContentsManager.save_script=False]
--expose-app-in-browserExpose the global app instance to browser via window.jupyterapp.Equivalent to: [--JupyterNotebookApp.expose_app_in_browser=True]
--custom-cssLoad custom CSS in template html files. Default is TrueEquivalent to: [--JupyterNotebookApp.custom_css=True]
--log-level=<Enum>Set the log level by value or name.Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']Default: 30Equivalent to: [--Application.log_level]
--config=<Unicode>Full path of a config file.Default: ''Equivalent to: [--JupyterApp.config_file]To see all available configurables, use `--help-all`.
我们这次可以使用--generate-config来生成一个默认的配置文件:
PS:可以看到配置文件路径的提示:
C:\Users\PC>jupyter notebook --generate-config
Writing default config to: C:\Users\PC\.jupyter\jupyter_notebook_config.py #生成的路径
用记事本打开文件,修改默认文件夹的配置:
将c.ServerApp.root_dir 设置为项目路径
保存并重启jupyter,可以看到即使是从C盘启动的jupyter,打开之后的目录是指定的目录
C:\Users\PC>
C:\Users\PC>jupyter notebook --generate-config
Writing default config to: C:\Users\PC\.jupyter\jupyter_notebook_config.py
PS:网上很多说法是设定c.ServerApp.notebook_dir = 'D:\jupyter_workspace',这个也可以。
配置文件里面提示说这个配置已经不推荐,推荐使用root_dir,所以我这边用的root_dir的方式设置的。
jupyter相关的文档可以从下面的help进入: