How to Connect to a Remote Jupyter Server in PyCharm
PyCharm Version: 2024.3
In this tutorial, I'll walk you through the steps to connect to a remote Jupyter server in PyCharm. I encountered some issues while setting this up, so I decided to write this guide to help others who might face similar problems.
Step 1: Install the Jupyter Package on the Remote Server
First, ensure that your virtual environment is activated. Then, install the jupyter
package by running the following command:
Next, start the Jupyter server by running the command below. Be sure you're in the correct terminal on the remote server:
Don't forget to activate your virtual environment first:
Step 2: Configure Jupyter
Navigate back to your root directory by running:
Then, list all files (including hidden ones) with:
You should see a file named jupyter_notebook_config.py
. Open it with the following command:
In the file, you'll see just one line: c = get_config() #noqa
. You'll need to add the following configuration lines:
c = get_config() #noqa
c.NotebookApp.ip = '*'
c.NotebookApp.port = 8888
c.ServerApp.open_browser = False
c.NotebookApp.token = '12345678' # Set your own token, which will be used later
After making the changes, press Ctrl+X
to exit and save the file.
Step 3: Start the Jupyter Server
Return to your server's terminal and start the Jupyter server by running:
Although you may come across various commands in other tutorials, this simple command will have the same effect.
Once started, you should see the following output:
Note the token=12345678
in the output, which corresponds to the token you set earlier.
Step 4: Connect to the Server from Your Local Machine
Now comes the crucial part: setting up a secure tunnel to forward the port from the remote server to your local machine.
In your local terminal, run the following command:
This will create a secure SSH tunnel from your local machine to the remote server.
Step 5: Connect to the Server in PyCharm
Finally, open PyCharm and enter the URL shown in Step 3. You should now be successfully connected to the remote Jupyter server. The url should look like this:
You are all set to start working with the remote Jupyter server!