要在Ubuntu上安装和配置Jupyter Notebook,请按照以下步骤操作:
首先,确保系统已更新。打开终端并运行以下命令:sudo apt updatesudo apt upgrade安装Python3和pip(Python包管理器)。运行以下命令:sudo apt install python3 python3-pip使用pip安装Jupyter。运行以下命令:pip3 install jupyter启动Jupyter Notebook。在终端中输入以下命令:jupyter notebook这将在您的默认Web浏览器中打开Jupyter Notebook。
(可选)为了能够从任何位置启动Jupyter Notebook,您可以创建一个启动脚本。创建一个名为jupyter_start.sh的文件,并在其中添加以下内容:#!/bin/bashjupyter notebook --no-browser --ip=0.0.0.0 --port=8888保存文件后,给予该脚本可执行权限:
chmod +x jupyter_start.sh现在,您可以通过运行./jupyter_start.sh来启动Jupyter Notebook。
jupyter.service的文件,并将其放置在/etc/systemd/system/目录中。在文件中添加以下内容:[Unit]Description=Jupyter Notebook[Service]Type=simplePIDFile=/run/jupyter.pidExecStart=/home/your_username/jupyter_start.shUser=your_usernameGroup=your_usernameWorkingDirectory=/home/your_usernameRestart=always[Install]WantedBy=multi-user.target将your_username替换为您的用户名。然后,重新加载systemd配置并启用服务:
sudo systemctl daemon-reloadsudo systemctl enable jupyter.service现在,Jupyter Notebook将在系统启动时自动运行。
若要访问远程计算机上的Jupyter Notebook,需要在启动Jupyter Notebook时生成一个密码。首先,生成一个密码文件:jupyter notebook password按提示输入密码。然后,编辑Jupyter配置文件。运行以下命令:
jupyter notebook --generate-config这将在~/.jupyter/jupyter_notebook_config.py生成一个配置文件。使用文本编辑器打开此文件,并取消以下行的注释(删除行首的#号):
c.NotebookApp.allow_remote_access = Truec.NotebookApp.ip = '0.0.0.0'c.NotebookApp.open_browser = Falsec.NotebookApp.port = 8888保存并关闭文件。现在,您应该能够通过远程计算机访问Jupyter Notebook。只需在Web浏览器中输入http://your_server_ip:8888,然后输入之前设置的密码即可。
现在,您已经在Ubuntu上成功安装并配置了Jupyter Notebook!


