How to use the preferred-dir parameter in jupyterlab

➜   jupyter lab --version
3.2.5

https://jupyterlab.readthedocs.io/en/stable/getting_started/changelog.html#id21
image

I did not find the preferred-dir parameter in the help manual
Should I use it this way?

 jupyter lab  --notebook-dir=/ --preferred-dir=/home/other_user
 ➜  jupyter lab --notebook-dir=/ --preferred-dir=/home/other_user
usage: jupyter-lab [-h] [--debug] [--show-config] [--show-config-json] [--generate-config]
                   [-y] [--allow-root] [--no-browser] [--autoreload] [--script]
                   [--no-script] [--core-mode] [--dev-mode] [--watch] [--splice-source]
                   [--expose-app-in-browser] [--extensions-in-dev-mode] [--collaborative]
                   [--log-level ServerApp.log_level] [--config ServerApp.config_file]
                   [--ip ServerApp.ip] [--port ServerApp.port]
                   [--port-retries ServerApp.port_retries]
                   [--transport KernelManager.transport] [--keyfile ServerApp.keyfile]
                   [--certfile ServerApp.certfile] [--client-ca ServerApp.client_ca]
                   [--notebook-dir ServerApp.root_dir] [--browser ServerApp.browser]
                   [--pylab ServerApp.pylab] [--gateway-url GatewayClient.url]
                   [extra_args ...]
jupyter-lab: error: unrecognized arguments: --preferred-dir=/home/other_user

➜   jupyter lab --help
JupyterLab - An extensible computational environment for Jupyter.

This launches a Tornado based HTML Server that serves up an HTML5/Javascript
JupyterLab client.

JupyterLab has three different modes of running:

* Core mode (`--core-mode`): in this mode JupyterLab will run using the JavaScript
  assets contained in the installed `jupyterlab` Python package. In core mode, no
  extensions are enabled. This is the default in a stable JupyterLab release if you
  have no extensions installed.
* Dev mode (`--dev-mode`): uses the unpublished local JavaScript packages in the
  `dev_mode` folder.  In this case JupyterLab will show a red stripe at the top of
  the page.  It can only be used if JupyterLab is installed as `pip install -e .`.
* App mode: JupyterLab allows multiple JupyterLab "applications" to be
  created by the user with different combinations of extensions. The `--app-dir` can
  be used to set a directory for different applications. The default application
  path can be found using `jupyter lab path`.

Subcommands
===========
Subcommands are launched as `lab cmd [args]`. For information on using
subcommand 'cmd', do: `lab cmd -h`.

build
clean
path
paths
workspace
workspaces

Options
=======
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

--debug
    Set debug level for the extension and underlying server applications.
    Equivalent to: [--ServerApp.log_level=DEBUG --ExtensionApp.log_level=DEBUG]
--show-config
    Show the application's configuration (human-readable format)
    Equivalent to: [--Application.show_config=True]
--show-config-json
    Show the application's configuration (json format)
    Equivalent to: [--Application.show_config_json=True]
--generate-config
    generate default config file
    Equivalent to: [--JupyterApp.generate_config=True]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--allow-root
    Allow the server to be run from root user.
    Equivalent to: [--ServerApp.allow_root=True]
--no-browser
    Prevent the opening of the default url in the browser.
    Equivalent to: [--ServerApp.open_browser=False --ExtensionApp.open_browser=False]
--autoreload
    Autoreload the webapp
        Enable reloading of the tornado webapp and all imported Python packages
        when any changes are made to any Python src files in server or
        extensions.
    Equivalent to: [--ServerApp.autoreload=True]
--script
    DEPRECATED, IGNORED
    Equivalent to: [--FileContentsManager.save_script=True]
--no-script
    DEPRECATED, IGNORED
    Equivalent to: [--FileContentsManager.save_script=False]
--core-mode
    Start the app in core mode.
    Equivalent to: [--LabApp.core_mode=True]
--dev-mode
    Start the app in dev mode for running from source.
    Equivalent to: [--LabApp.dev_mode=True]
--watch
    Start the app in watch mode.
    Equivalent to: [--LabApp.watch=True]
--expose-app-in-browser
    Expose the global app instance to browser via window.jupyterlab.
    Equivalent to: [--LabApp.expose_app_in_browser=True]
--extensions-in-dev-mode
    Load prebuilt extensions in dev-mode.
    Equivalent to: [--LabApp.extensions_in_dev_mode=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: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--ip=<Unicode>
    The IP address the Jupyter server will listen on.
    Default: 'localhost'
    Equivalent to: [--ServerApp.ip]
--port=<Int>
    The port the Jupyter server will listen on.
    Default: 8888
    Equivalent to: [--ServerApp.port]
--port-retries=<Int>
    The number of additional ports to try if the specified port is not
    available.
    Default: 50
    Equivalent to: [--ServerApp.port_retries]
--keyfile=<Unicode>
    The full path to a private key file for usage with SSL/TLS.
    Default: ''
    Equivalent to: [--ServerApp.keyfile]
--certfile=<Unicode>
    The full path to an SSL/TLS certificate file.
    Default: ''
    Equivalent to: [--ServerApp.certfile]
--client-ca=<Unicode>
    The full path to a certificate authority certificate for SSL/TLS client
    authentication.
    Default: ''
    Equivalent to: [--ServerApp.client_ca]
--notebook-dir=<Unicode>
    The directory to use for notebooks and kernels.
    Default: ''
    Equivalent to: [--ServerApp.root_dir]
--browser=<Unicode>
    Specify what command to use to invoke a web
                          browser when starting the server. If not specified, the
                          default browser will be determined by the `webbrowser`
                          standard library module, which allows setting of the
                          BROWSER environment variable to override it.
    Default: ''
    Equivalent to: [--ServerApp.browser]
--pylab=<Unicode>
    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
    Default: 'disabled'
    Equivalent to: [--ServerApp.pylab]
--watch=<Bool>
    Whether to serve the app in watch mode
    Default: False
    Equivalent to: [--LabApp.watch]
--app-dir=<Unicode>
    The app directory to launch JupyterLab from.
    Default: None
    Equivalent to: [--LabApp.app_dir]

Examples
--------

    jupyter lab                       # start JupyterLab
            jupyter lab --dev-mode            # start JupyterLab in development mode, with no extensions
            jupyter lab --core-mode           # start JupyterLab in core mode, with no extensions
            jupyter lab --app-dir=~/myjupyterlabapp # start JupyterLab with a particular set of extensions
            jupyter lab --certfile=mycert.pem # use SSL/TLS certificate

To see all available configurables, use `--help-all`.

As described in the PR which introduced support for --preferred-dir in JupyterLab, it had an accompanying PR to jupyter-server which was merged and released in 1.10.0. What version of jupyter-server do you have installed? You can check that by running jupyter server --version.

I checked the version of my jupyter server

➜   jupyter server --version
1.4.1
 ➜   jupyter --version
Selected Jupyter core packages...
IPython          : 7.29.0
ipykernel        : 6.4.1
ipywidgets       : not installed
jupyter_client   : 7.0.6
jupyter_core     : 4.9.1
jupyter_server   : 1.4.1
jupyterlab       : 3.2.5
nbclient         : 0.5.3
nbconvert        : 6.1.0
nbformat         : 5.1.3
notebook         : 6.4.6
qtconsole        : not installed
traitlets        : 5.1.1

But in the parameters of jupyter service, I still did not find the preferred-dir parameter

➜  jupyter server --help
The Jupyter Server.

    This launches a Tornado-based Jupyter Server.

Subcommands
===========
Subcommands are launched as `jupyter-server cmd [args]`. For information on
using subcommand 'cmd', do: `jupyter-server cmd -h`.

list
    List currently running notebook servers.
stop
    Stop currently running Jupyter server for a given port
password
    Set a password for the Jupyter server.
extension
    Work with Jupyter server extensions

Options
=======
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

--debug
    Set debug level for the extension and underlying server applications.
    Equivalent to: [--ServerApp.log_level=DEBUG --ExtensionApp.log_level=DEBUG]
--show-config
    Show the application's configuration (human-readable format)
    Equivalent to: [--Application.show_config=True]
--show-config-json
    Show the application's configuration (json format)
    Equivalent to: [--Application.show_config_json=True]
--generate-config
    generate default config file
    Equivalent to: [--JupyterApp.generate_config=True]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--allow-root
    Allow the server to be run from root user.
    Equivalent to: [--ServerApp.allow_root=True]
--no-browser
    Prevent the opening of the default url in the browser.
    Equivalent to: [--ServerApp.open_browser=False --ExtensionApp.open_browser=False]
--autoreload
    Autoreload the webapp
        Enable reloading of the tornado webapp and all imported Python packages
        when any changes are made to any Python src files in server or
        extensions.
    Equivalent to: [--ServerApp.autoreload=True]
--script
    DEPRECATED, IGNORED
    Equivalent to: [--FileContentsManager.save_script=True]
--no-script
    DEPRECATED, IGNORED
    Equivalent to: [--FileContentsManager.save_script=False]
--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: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--ip=<Unicode>
    The IP address the Jupyter server will listen on.
    Default: 'localhost'
    Equivalent to: [--ServerApp.ip]
--port=<Int>
    The port the Jupyter server will listen on.
    Default: 8888
    Equivalent to: [--ServerApp.port]
--port-retries=<Int>
    The number of additional ports to try if the specified port is not
    available.
    Default: 50
    Equivalent to: [--ServerApp.port_retries]
--transport=<CaselessStrEnum>
    Choices: any of ['tcp', 'ipc'] (case-insensitive)
    Default: 'tcp'
    Equivalent to: [--KernelManager.transport]
--keyfile=<Unicode>
    The full path to a private key file for usage with SSL/TLS.
    Default: ''
    Equivalent to: [--ServerApp.keyfile]
--certfile=<Unicode>
    The full path to an SSL/TLS certificate file.
    Default: ''
    Equivalent to: [--ServerApp.certfile]
--client-ca=<Unicode>
    The full path to a certificate authority certificate for SSL/TLS client
    authentication.
    Default: ''
    Equivalent to: [--ServerApp.client_ca]
--notebook-dir=<Unicode>
    The directory to use for notebooks and kernels.
    Default: ''
    Equivalent to: [--ServerApp.root_dir]
--browser=<Unicode>
    Specify what command to use to invoke a web
                          browser when starting the server. If not specified, the
                          default browser will be determined by the `webbrowser`
                          standard library module, which allows setting of the
                          BROWSER environment variable to override it.
    Default: ''
    Equivalent to: [--ServerApp.browser]
--pylab=<Unicode>
    DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
    Default: 'disabled'
    Equivalent to: [--ServerApp.pylab]
--gateway-url=<Unicode>
    The url of the Kernel or Enterprise Gateway server where
            kernel specifications are defined and kernel management takes place.
            If defined, this Notebook server acts as a proxy for all kernel
            management and kernel specification retrieval.  (JUPYTER_GATEWAY_URL env var)
    Default: None
    Equivalent to: [--GatewayClient.url]

Examples
--------

    jupyter server                       # start the server
    jupyter server  --certfile=mycert.pem # use SSL/TLS certificate
    jupyter server password              # enter a password to protect the server

To see all available configurables, use `--help-all`.

This means that you need to upgrade jupyter-server to version 1.10.0 or newer. You have a very old 1.4.1 installed.

1 Like

Thank you very much, I upgraded jupyter-server

➜  jupyter --version                                                               
Selected Jupyter core packages...
IPython          : 7.30.1
ipykernel        : 5.5.5
ipywidgets       : not installed
jupyter_client   : 7.1.0
jupyter_core     : 4.9.1
jupyter_server   : 1.13.1
jupyterlab       : 3.2.5
nbclient         : 0.5.9
nbconvert        : 6.3.0
nbformat         : 5.1.3
notebook         : 6.4.6
qtconsole        : not installed
traitlets        : 5.1.1

tree

/home/
├── other_user
│   └── hi.txt
└── user
    └── getting_started.ipynb

solution

 ➜   jupyter lab  --notebook-dir='/home' --preferred-dir='/home/other_user'

Is there a bug?

jupyter lab --notebook-dir='/' --preferred-dir='/home/other_user'

wrong way

jupyter lab --notebook-dir='/home' --preferred-dir='other_user'

jupyter lab --notebook-dir='/home' --preferred-dir='./other_user'

[C 2021-12-22 22:16:22.818 ServerApp] Bad config encountered during initialization: No such preferred dir: ''/other_user''

But Not every time the error message is displayed correctly

[C 2021-12-22 22:11:45.671 ServerApp] Bad config encountered during initialization: preferred_dir must be equal or a subdir of root_dir: ''/user''
1 Like

Thank you, yes, I believe that it should not be like that:

1 Like
1 Like