1

I'm trying to run Jupyter notebooks from WSL (Windows Subsystem For Linux). The default port it uses is localhost:8888

However if I try to reach that in my browser, nothing happens.

If I start Jupyter with jupyter notebook --port 8080, I can connect with localhost:8080 with no problems.

So I think this is a firewall problem. I am running Windows Defender but am pretty clueless with it. I tried setting an Incoming Rule to allow port 8888, following the instructions here but it didn't help. Then I tried adding an Outgoing Rule as well, but that didn't help either.

I'm probably doing something very simple wrong.

Any ideas?

0

First, let have some prior knowledge about how to get WSL distribution binary path. See any of these Q&A from SuperUser:

After installing jupyter notebook in WSL, resolve the full path of python binary. Get the distribution installed path from previous answer and append these ones:

  • Python2: \rootfs\usr\bin\python2.7
  • Python3: \rootfs\usr\bin\python3.5

The full path will be like this:

C:\Users\%USERNAME%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\bin\python3.5 

Too long, isn't it? Now allow it in Windows Firewall. It is possible with Windows Firewall Management Console (wf.msc). Here netsh command is used. Run this command as administrator:

netsh advfirewall firewall add rule Name=Python Program="put-the-path-here" LocalPort=8888 Action=allow Dir=Out 

Or with PowerShell:

New-NetFirewallRule -DisplayName "Python" -Name "Python" -Direction Outbound -Program "put-the-path-here" LocalPort 8888 -Action Allow 

This will allow port 8888 for that python binary. If the Windows side browser is also firewall-ed then allow it to accept the connection. For further details, see netsh and New-NetFirewallRule command syntax.

  • Thanks for the suggestions... unfortunately this doesn't work for me. The -LocalPort 8888 part returns an error saying you couldn't set this without a protocol, so I set the Protocol to TCP. Also tried setting it (inbound and outbound) for /home/me/anaconda3/bin/python3.7 which is the version I suspect Jupyter uses. Turned on firewall logging, but don't see any events even when I connect to 8080... so maybe it's not a firewall issue after all? – Luigi Plinge Mar 18 '19 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.