Skip to content

Instantly share code, notes, and snippets.

@shhommychon
Last active October 17, 2024 14:45
Show Gist options
  • Select an option

  • Save shhommychon/27a756e3d601b5cc556c64ac3eedd995 to your computer and use it in GitHub Desktop.

Select an option

Save shhommychon/27a756e3d601b5cc556c64ac3eedd995 to your computer and use it in GitHub Desktop.
내가 안까먹을라고 적어놓는 우분투 쥬피터랩 설정 팁들
  1. Install jupyterlab on Ubuntu without conda.
# sudo apt update  # if needed
# sudo apt install python3-pip python3-dev  # if needed
pip3 install jupyterlab
  1. Generate a Jupyter configuration file and modify.

    # Create a configuration file at `~/.jupyter/jupyter_lab_config.py`.
    jupyter lab --generate-config
    
    # Open the configuration file in a text editor.
    vi ~/.jupyter/jupyter_lab_config.py
    • ex1) Change the port.

      # find the line in `~/.jupyter/jupyter_lab_config.py`
      c.ServerApp.port = 8888  # uncomment and change to desired port

      Or, alternatively, set the port temporarily.

      jupyter lab --port=8888
    • ex2) Set the password.

      from jupyter_server.auth import passwd
      passwd(algorithm='sha1')  # enter desired password to input.
      # find the line in `~/.jupyter/jupyter_lab_config.py`
      c.ServerApp.password = 'sha1:7ddaddc0d166:b2f60bec76c286c2a68b2d703cf2a24db2a5d3f5'  # example when password is set to '1234'

      Or, alternatively, set the password temporarily.

      jupyter lab --NotebookApp.token='1234'  # example when password is set to '1234'
    • ex3) Set the root directory.

      # find the line in `~/.jupyter/jupyter_lab_config.py`
      c.ServerApp.root_dir = '/path/to/your/directory'  # uncomment and change to desired directory

      Or, alternatively, set the root directory temporarily.

      jupyter lab --notebook-dir=/path/to/your/directory
      # or
      jupyter lab --LabApp.root_dir=/path/to/your/directory
  2. Use a virtual environment as a jupyter kernel.

    • Register kernel.

      1. Activate the virtual environment.

        source /path/to/venv/bin/activate
      2. Install ipykernel in the virtual environment.

        pip install ipykernel
      3. Add the virtual environment as a kernel.

        # Run the code while virtual environment is still active.
        python -m ipykernel install --user --name name_of_kernel --display-name "Kernel Name"
    • Unregister kernel.

      1. View the list of all registered jupyter kernels.

        jupyter kernelspec list
      2. Remove the virtual environment from jupyter.

        jupyter kernelspec uninstall name_of_kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment