Python >> Tutoriel Python >  >> Python Tag >> Linux

Utilisation de Jupyter avec le sous-système Windows pour Linux

essayez :

jupyter notebook --no-browser

Attribuez manuellement un numéro de port différent lorsque vous démarrez le notebook. Par exemple :

jupyter notebook --port=8889


J'ai eu un problème similaire avec le navigateur, j'ai reçu

No web browser found: could not locate runnable browser.

J'ai installé WSLU https://github.com/wslutilities/wslu.Ensuite, j'ai reçu

Start : This command cannot be run due to the error: The system cannot find the file specified.
At line:1 char:1
+ Start --h
+ ~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

jupyter-notebook ne fournit pas l'url en paramètre de wlsview . Il passe un chemin avec le fichier au navigateur. par exemple

file:///home/myhome/.local/share/jupyter/runtime/nbserver-5058-open.html

avec l'URL réelle

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="1;url=http://localhost:8888/tree?token=19b5f1fefb13f5fc315b05991175d1f8cb5ada9baaca6804" />
    <title>Opening Jupyter Notebook</title>
</head>
<body>

<p>
    This page should redirect you to Jupyter Notebook. If it doesn't,
    <a href="http://localhost:8888/tree?token=19b5f1fefb13f5fc315b05991175d1f8cb5ada9baaca6804">click here to go to Jupyter</a>.
</p>

</body>
</html>

Créer un fichier jupyter-notebook-browser avec un contenu pour extraire l'url réelle

#!/bin/bash
file=$(echo "$1" | sed 's/file:\/\///')
url=$(grep -oP 'href="\K([^"]*localhost[^"]+)' "$file")
wslview "$url"

puis exécutez jupyter-notebook --browser=jupyter-notebook-browser

ou définissez BROWSER variable et exécuter

export BROWSER="jupyter-notebook-browser"
jupyter-notebook