Skip to content

ShivamKR12/codeserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Setting Up Jupyter Lab on Google Colab

This guide will walk you through the steps to set up Jupyter Lab with necessary extensions, GPU support, and expose it using Cloudflare on Google Colab.

Requirements

Google Colab environment

Steps

Step 1: Install Jupyter Lab and Required Packages

First, install Jupyter Lab and other required packages: !pip install jupyterlab jupyterlab-code-formatter jupyterlab-lsp python-lsp-server[all]

Step 2: Install Cloudflare to Expose the Jupyter Lab Server

!wget -P ~ https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb !dpkg -i ~/cloudflared-linux-amd64.deb

Step 3: Install Jupyter Lab Extensions

Install the language server and code formatter extensions:

!jupyter labextension install @krassowski/jupyterlab-lsp !jupyter labextension install @ryantam626/jupyterlab_code_formatter

Step 4: Enable Jupyter Lab Extensions

Enable the code formatter server extension:

!jupyter serverextension enable --py jupyterlab_code_formatter

Step 5: Install GPU Packages (TensorFlow, PyTorch)

!pip install tensorflow-gpu !pip install torch torchvision torchaudio

Step 6: Generate Jupyter Lab Configuration

Generate the default Jupyter Lab configuration file:

!jupyter lab --generate-config

Step 7: Configure Jupyter Lab

Append the following configuration to your jupyter_lab_config.py:

`config_path = "/root/.jupyter/jupyter_lab_config.py" with open(config_path, "a") as config_file: config_file.write("""

Add the following lines to your jupyter_lab_config.py

c.ServerApp.port = 8888 c.ServerApp.open_browser = False c.ServerApp.ip = '0.0.0.0' c.ServerApp.allow_remote_access = True c.ServerApp.token = '' # No token authentication c.ServerApp.password = '' # No password authentication c.LspInstallSettings.install_optional_dependencies = True

Configure code formatter

c.CodeFormatter.formatters = { 'python': ['black'], }

Enable GPU support

c.NotebookApp.kernel_spec_manager_class = 'nb_conda_kernels.CondaKernelSpecManager'

Save notebook state

c.NotebookApp.shutdown_no_activity_timeout = 3600 c.NotebookApp.terminals_enabled = True """)`

Step 8: Start Cloudflare

Set up a tunnel for the Jupyter Lab server:

`import subprocess import threading import time import socket

def iframe_thread(port): while True: time.sleep(0.5) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex(('127.0.0.1', port)) if result == 0: break sock.close()

print("\nJupyter Lab finished loading, trying to launch cloudflared...\n")

# Start Cloudflare tunnel
p = subprocess.Popen(["cloudflared", "tunnel", "--url", f"http://127.0.0.1:{port}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in p.stderr:
    l = line.decode()
    if "trycloudflare.com" in l:
        print("This is the URL to access Jupyter Lab:", l[l.find("http"):], end='')

Start the thread to monitor Jupyter Lab

threading.Thread(target=iframe_thread, daemon=True, args=(8888,)).start()`

Step 9: Start Jupyter Lab Server

Finally, start the Jupyter Lab server:

!jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root

About

a jupyter labs code server on google colab

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published