【原创】Ubuntu 使用 pip3 安装 jupyterlab

2024-06-15 20:08

本文主要是介绍【原创】Ubuntu 使用 pip3 安装 jupyterlab,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

安装准备

1、什么是 JupyterLab?

JupyterLab is a web-based interactive development environment for Jupyter notebooks, code, and data. JupyterLab is flexible: configure and arrange the user interface to support a wide range of workflows in data science, scientific computing, and machine learning. JupyterLab is extensible and modular: write plugins that add new components and integrate with existing ones.

上面的话来自于 jupyter 官网,下面是我的翻译加理解。

首先,Jupyterlab 是一款基于 Web 的交互式开发环境,主要用于 Jupyter notebooks,开发代码和处理数据。JupyterLab 非常地灵活,只需要通过用户界面配置便可以支持非常宽泛的工作流程,包括数据科学,科学计算和机器学习等场景。而且 JupyterLab 也是可扩展且支持模块化集成的,你可以编写插件来添加新的组件和功能并且将这些插件都集成到一起。

简单来说,JupyterLab 提供一个基于 Web 的便捷开发环境,你可以在 Web 网页上编写与调试你的代码、数据、程序等。较多的场景是使用在数据科学领域,但其他很多领域也完全适用。

2、什么是 Jupyter Notebook?

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

Jupyter Notebook 是 JupyterLab 中的一个功能,Jupyter Notebook 简单来说就是一个代码及其结果的记事本,你可以通过 Jupyter Notebook 创建一篇文档用来阐述你的某个功能或者某个想法的代码实现过程。

Jupyter Notebook 的使用场景也非常的广,数据清洗与数据回去的,数值模拟,统计建模,数据可视化,机器学习等等。

使用 Jupyter Notebook 你还可以把你把的代码或者功能模块的结果保存为一个文档(文件),然后你可以把他分享给其他人,能够非常方便给实现知识记录与分享。

3、安装环境

Ubuntu 18.04.5
Python 3.8.5
Pip3 20.0.2
Jupyter-lab 2.2.8

4、安装规划

本文计划在我家里的一台服务器设备(Ubuntu 18.04 虚拟机)上安装一个 JupyterLab 的服务,并且让其持续在后台运行,然后通过内网穿透将其发布到外网。这样,我就可以在我的任何有浏览器的设备上访问 JupyterLab 的 Web 服务来进行我需要的开发与工作了,赞~

安装步骤

1、安装 jupyterlab

jupyterlab 的安装可以说非常简单了可以使用 pip3 执行如下命令安装 jupyterlab

pip3 install jupyterlab

示例:

$ pip3 install jupyterlab -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Collecting jupyterlabDownloading https://pypi.doubanio.com/packages/d7/a9/d7c904ee406d1ce320fd1d91e05111fa158e66bb217f68d070b5f58c5937/jupyterlab-2.2.8-py3-none-any.whl (7.8 MB)|████████████████████████████████| 7.8 MB 8.8 MB/s
...
...
Successfully built tornado pyrsistent pandocfilters
Installing collected packages: json5, urllib3, certifi, idna, chardet, requests, pyrsistent, attrs, jsonschema, tornado, pyzmq, ipython-genutils, traitlets, jupyter-core, python-dateutil, jupyter-client, prometheus-client, backcall, pygments, decorator, ptyprocess, pexpect, parso, jedi, pickleshare, wcwidth, prompt-toolkit, appnope, ipython, ipykernel, testpath, pyparsing, packaging, webencodings, bleach, entrypoints, defusedxml, nbformat, async-generator, nest-asyncio, nbclient, jupyterlab-pygments, mistune, pandocfilters, nbconvert, terminado, Send2Trash, pycparser, cffi, argon2-cffi, notebook, jupyterlab-server, jupyterlab
Successfully installed Send2Trash-1.5.0 appnope-0.1.0 argon2-cffi-20.1.0 async-generator-1.10 attrs-20.2.0 backcall-0.2.0 bleach-3.2.1 certifi-2020.6.20 cffi-1.14.3 chardet-3.0.4 decorator-4.4.2 defusedxml-0.6.0 entrypoints-0.3 idna-2.10 ipykernel-5.3.4 ipython-7.18.1 ipython-genutils-0.2.0 jedi-0.17.2 json5-0.9.5 jsonschema-3.2.0 jupyter-client-6.1.7 jupyter-core-4.6.3 jupyterlab-2.2.8 jupyterlab-pygments-0.1.2 jupyterlab-server-1.2.0 mistune-0.8.4 nbclient-0.5.1 nbconvert-6.0.7 nbformat-5.0.8 nest-asyncio-1.4.1 notebook-6.1.4 packaging-20.4 pandocfilters-1.4.2 parso-0.7.1 pexpect-4.8.0 pickleshare-0.7.5 prometheus-client-0.8.0 prompt-toolkit-3.0.8 ptyprocess-0.6.0 pycparser-2.20 pygments-2.7.1 pyparsing-2.4.7 pyrsistent-0.17.3 python-dateutil-2.8.1 pyzmq-19.0.2 requests-2.24.0 terminado-0.9.1 testpath-0.4.4 tornado-6.0.4 traitlets-5.0.5 urllib3-1.25.11 wcwidth-0.2.5 webencodings-0.5.1

注:这里也可以使用 sudo 权限安装 jupyterlab,这样所有用户都能使用 jupyterlab,而且也不用下方的配置环境变量的步骤。

2、配置环境变量

如果不使用 sudo 权限进行安装,也可以安装完成,但可能会提示如下告警,而且直接运行 jupyter-lab 命令可能会提示找不到命令。

安装警告信息:

WARNING: The scripts jupyter, jupyter-migrate and jupyter-troubleshoot are installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The scripts jupyter-kernel, jupyter-kernelspec and jupyter-run are installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script jsonschema is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script jupyter-trust is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script pygmentize is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script jupyter-nbconvert is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The scripts iptest, iptest3, ipython and ipython3 are installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The scripts jupyter-bundlerextension, jupyter-nbextension, jupyter-notebook and jupyter-serverextension are installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script chardetect is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The script pyjson5 is installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.WARNING: The scripts jlpm, jupyter-lab, jupyter-labextension and jupyter-labhub are installed in '/home/jiangzl/.local/bin' which is not on PATH.Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

如下图所示:

$ juypyter-lab
bash: juypyter-lab: command not found

按照警告信息中的提示,只需要将 ‘/home/jiangzl/.local/bin’ 目录添加到环境变量的 PATH 变量中即可。

执行如下命令添加环境变量

echo 'PATH=$PATH:'${HOME}'/.local/bin' | sudo tee -a /etc/profile

示例:

$ echo 'PATH=$PATH:'${HOME}'/.local/bin' | sudo tee -a /etc/profile
[sudo] password for jiangzl:
PATH=$PATH:/home/jiangzl/.local/bin

注:

(1) 这里我将 /home/jiangzl 用环境变量 ${HOME} 来代替了,这样就算是用户名不相同也不用替换直接执行上面的命令即可。

(2) 如果你没有警告信息,也可以执行 jupyter-lab 命令,则不必进行上面的配置。

3、使用环境变量生效

$ source /etc/profile

至此,jupyterlab 的安装就完成了,可以说是十分简单了。

运行验证

1、验证安装

执行如下命令,如果成功显示版本号,则表示安装配置已经成功。

$ jupyter-lab -V
2.2.8

2、运行

执行如下命令即可以在前台运行一个 jupyter-lab server,然后你就可以在浏览器中访问服务来使用了。

jupyter-lab

示例:

$ cd ~
$ mkdir -p ~/Workspace/jupyterlab
$ cd ~/Workspace/jupyterlab
$ pwd
/home/jiangzl/Workspace/jupyterlab
$ nohup jupyter-lab --ip=0.0.0.0 --port=8888 >> ./jupyterlab.log 2>&1 &
[1] 5450

注:

(1) 运行 jupyter-lab 命令的目录即被作为 jupyter-lab 的 notebook 的目录,也就是说你从 jupyterlab 界面创建的 notebook,markdow 等文件都将存在于 jupyter-lab 命令运行所在的目录~

(2) 默认情况下,jupyterlab 监听 localhost 的 8888 端口,只能在本机访问。当然也可以通过上面示例代码进行传参来控制监听的 IP 与 Port。0.0.0.0 表示可以从任意位置请求该服务,如果你只在本机使用,则执行如下命令即可:

$ nohup jupyter-lab >> ./jupyterlab.log 2>&1 &

(3) 默认情况下,监听 localhost 以及从本机访问时,不需要 token 或者密码,但如果从远程访问,则需要 token 或者密码。

3、查看运行日志

验证安装是否完成,比如查看日志,查看进程等

$ pwd
/home/jiangzl/Workspace/jupyterlab
$ -100f jupyterlab.log
[I 11:55:13.548 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.6/dist-packages/jupyterlab
[I 11:55:13.548 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[I 11:55:13.550 LabApp] Serving notebooks from local directory: /home/jiangzl/Workspace/jupyterlab
[I 11:55:13.550 LabApp] Jupyter Notebook 6.1.4 is running at:
[I 11:55:13.550 LabApp] http://ubuntu:8888/?token=e8a370327d94b7fe8f951a70468a0147f2c577
[I 11:55:13.550 LabApp]  or http://127.0.0.1:8888/?token=e8a370327d94b7fe8f951a70468a0147f2c577
[I 11:55:13.550 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 11:55:13.552 LabApp] No web browser found: could not locate runnable browser.
[C 11:55:13.552 LabApp]To access the notebook, open this file in a browser:file:///home/jiangzl/.local/share/jupyter/runtime/nbserver-525722-open.htmlOr copy and paste one of these URLs:http://ubuntu:8888/?token=e8a370327d94b7fe8f951a70468a0147f2c577or http://127.0.0.1:8888/?token=e8a370327d94b7fe8f951a70468a0147f2c577

4、访问

使用 jupyter-lab 运行的情况下默认开启 8888 端口,所以你可以在浏览器输入 http://ip:port/lab 来访问 jupyter lab,如下示例:

注:初次从外网访问时,默认的 token 可从 log 中获取,http://127.0.0.1:8888/?token=e8a370327d94b7fe8f951a70468a0147f2c577 日志中类似这样的 URL 后面的 token= 后面的部分就是我们初始登录的 token 值。

输入 token 值并设置新的密码,以后就使用密码进行登录了。

登录进来啦~ 右侧是 Jupyterlab 默认支持的使用场景,可以看到支持 Notebook,Python Console,Terminal,Markdown file 等等。

5、简单使用

点击 File -> New -> Notebook -> 选择 Python3

Hello Jupyter 已经运行成功了!

6、关闭与重启 jupyterlab

由于 jupyterlab 没有提供关闭与重启的命令。因此,只能通过 kill -TERM 的方式来进行关闭与重启

关闭命令

ps -ef | grep jupyter-lab | grep -v grep | awk '{print $2}' | xargs kill -TERM

示例:

$ ps -ef | grep jupyter-lab | grep -v grep | awk '{print $2}' | xargs kill -TERM
[1]+  Done                    nohup jupyter-lab --ip=0.0.0.0 --port=8888 >> ./jupyterlab.log

重启就是先关闭再执行一次重启命令。

7、总结

虽然我写了一大堆,但其实 jupyterlab 的安装真的是超级简单,而且非常好用,建议你也试试吧。

另外,其实我本人的 Jupyterlab 是在 docker 中运行的,后面抽时间我把对应的 Docker 运行的 Dockerfile 分享出来并把镜像提交到仓库中~

附录

https://jupyter.org/
https://jupyter.org/install

这篇关于【原创】Ubuntu 使用 pip3 安装 jupyterlab的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1064450

相关文章

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

在Windows上使用qemu安装ubuntu24.04服务器的详细指南

《在Windows上使用qemu安装ubuntu24.04服务器的详细指南》本文介绍了在Windows上使用QEMU安装Ubuntu24.04的全流程:安装QEMU、准备ISO镜像、创建虚拟磁盘、配置... 目录1. 安装QEMU环境2. 准备Ubuntu 24.04镜像3. 启动QEMU安装Ubuntu4

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/