Connecting to JupyterHub using Visual Studio Code
This guide will help you connect to a JupyterHub server in the cloud using VS Code installed on your local workstation. This way, you can use powerful cloud servers that outperform your local laptop to run resource-intensive computations.
You can deploy JupyterHub in the cloud on a VM with multiple GPUs, dozens of cores, and hundreds of gigabytes of RAM.
To get started with JupyterHub via Visual Studio Code on your local computer, follow these steps:
-
Obtain a JupyterHub access token.
-
Log in to JupyterHub by entering your username and password.
-
Go to the Hub Control Panel. You can find this option by selecting File -> Hub Control Panel. Then go to the Token tab by selecting this item at the top of the menu.
-
Enter a description for the new token, select the token expiration period, and click «Request new API token».
-
Copy the generated token and store it in a safe place. You should treat it as the password for your JupyterHub. You can and should revoke the token using the same Hub Control Panel section when you stop using it.
-
-
Connect VS Code to the JupyterHub instance in the cloud.
-
Open the command palette in Visual Studio Code (CMD+SHIFT+P on MacOS, CTRL+SHIFT+P on other OSes).
-
Select «Python: Specify local or remote Jupyter server for connections».
-
Generate a server URL of the form
https://<your-hub-url>/jh/user/<your-hub-user-name>/?token=<your-token>.Example:
https://ml-platform-3c000000000000.ml.msk.vkcs.cloud/jh/user/admin/?token=000f00bdf7d00fbd0000000c0006ebfd
-
-
(Optional) Install the Jupyter Extension extension for VS Code.
-
Verify the created connection.
Create or open a new Notebook in VS Code. Its Kernel will now run on your cloud JupyterHub.
You can verify this by running the
!hostnamecommand, which should return the hostname of your remote JupyterHub server instead of your local hostname.You can also try importing libraries that are located on the remote JupyterHub server but not in your local environment.