远程Putty连接Linux运行Jupyter Notebook遇JS启用问题求助
Hey there! I get that starting out with remote Jupyter on Linux can feel a bit tricky—let's walk through solving this Javascript error and getting your Python scripts up and running smoothly.
Why You're Seeing the Javascript Error
When you run jupyter notebook directly in PuTTY, you're trying to use Jupyter's browser-based interface through a command-line terminal. Terminals don't support Javascript at all, which is why that error pops up. The fix is to configure Jupyter to let you access it from your local browser (which natively supports Javascript).
Step 1: Configure Jupyter for Remote Access
First, we need to set up Jupyter to accept connections from outside the remote machine:
- Generate a Jupyter config file if you don't already have one:
jupyter notebook --generate-config - Open the config file with a text editor (I'll use
vimhere, butnanoworks too if you prefer simpler tools):vim ~/.jupyter/jupyter_notebook_config.py - Find and modify these settings (remove the
#comment at the start of each line to activate them):c.NotebookApp.ip = '*'– Allows connections from any IP addressc.NotebookApp.open_browser = False– Prevents the remote machine from trying to open a browser (it can't access one via PuTTY anyway)c.NotebookApp.port = 8888– Uses Jupyter's default port; if this port is already in use, pick another number like 8889
- (Optional but highly recommended) Set a password to secure your Jupyter instance:
Follow the prompts to create a password—you'll need this later to log in from your local browser.jupyter notebook password
Step 2: Start Jupyter in a Persistent Session
If you close PuTTY, your Jupyter session will stop unless you use a tool to keep it running in the background. Let's use screen (a popular terminal multiplexer):
- Install
screenif it's not already on your remote machine:- For Debian/Ubuntu:
sudo apt update && sudo apt install screen - For CentOS/RHEL:
sudo yum install screen
- For Debian/Ubuntu:
- Create a new screen session named "jupyter":
screen -S jupyter - Set your Anaconda path (we'll make this permanent later—see the tip below):
export PATH="/share/apps/packages/anaconda2/bin:$PATH" - Start Jupyter Notebook:
jupyter notebook - Detach the screen session so it keeps running even if you close PuTTY: press
Ctrl+AthenD. To reattach later (e.g., to stop Jupyter), runscreen -r jupyter.
Step 3: Access Jupyter from Your Local Browser
Now, connect to Jupyter using your local computer's browser:
- Open any modern browser (Chrome, Firefox, Edge—all have Javascript enabled by default)
- Type in the URL:
http://[remote-machine-ip]:8888(replace[remote-machine-ip]with the actual IP address of your remote server) - Enter the password you set earlier (if you completed Step 1.4)
- You'll now see the full Jupyter dashboard—no more Javascript errors here!
Running Your Python Scripts in Jupyter
Once you're in the Jupyter dashboard:
- To create a new notebook: Click the
Newbutton in the top-right corner, then selectPython 2(since you're using Anaconda2) - To run code in a notebook: Type your Python code into a cell, then press
Shift+Enterto execute it. The output will show up right below the cell. - To upload an existing Python script: Click the
Uploadbutton in the top-right, select your.pyfile from your local computer, then click the uploaded file to open it in Jupyter (you can run or edit it from there).
Quick Extra Tip: Make Anaconda Path Permanent
Instead of typing the export PATH command every time you log in, add it to your ~/.bashrc file to set it automatically:
echo 'export PATH="/share/apps/packages/anaconda2/bin:$PATH"' >> ~/.bashrc source ~/.bashrc
Important Note: Firewall Settings
Make sure your remote machine's firewall allows incoming connections on port 8888 (or whatever port you chose). For example, on Ubuntu with ufw:
sudo ufw allow 8888/tcp
内容的提问来源于stack exchange,提问作者ZEESHAN

