JupyterLab notebook环境在Ubuntu24.04下的安装和Windows 10下vscode远程使用jupyter

JupyterLab notebook环境在Ubuntu24.04下的安装,并在Windows 10下通过vscode远程使用jupyter

安装jupyter Lab

首先,创建python环境(可选)

python -m venv py312

激活环境

source py312/bin/activate

安装jupyterlab

pip install jupyterlab

启动服务

jupyter-lab --ip 0.0.0.0

启动后,会给出带token的连接jupyternotebook的链接,直接输入浏览器即可。

如果浏览器和服务器是不同的主机,主机名没有解析的话,则可能需要使用ip地址来连接,比如服务器的ip地址是:172.25.183.186

那么连接则是:

http://172.25.183.186:8888/lab
带token的则是:
http://172.25.183.186:8888/lab?token=8508e5ec00939cdc9d710c5ff215463fd0d156810f701d97

jupyter lab设置

添加多个python内核

到新的python venv环境

比如python3.10环境下,想把当前这个python3.10内核注册到jupyter里面去,

那就在python3.10环境下执行

python -m ipykernel --version
python -m ipykernel install --user --name=py310

如果没有安装ipykernel,则pip安装:

pip install ipykernel

测试

在jupyter系统内核里选择py310,发现首先python解释器工作正常。

原来的python3.12的内核飞桨和paddlex无法正常使用,所以现在只要这两者能正常使用,就证明python3.10内核注册上了。

安装padlle

python -m pip install paddlepaddle==3.0.0b2 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/

安装paddlex

pip install paddlex==3.0.0b2

快速验证

paddlex --pipeline OCR --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png --device cpu

验证成功

paddlex --pipeline OCR --input https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png --device cpu

Using official model (PP-OCRv4_mobile_det), the model files will be be automatically downloaded and saved in /home/skywalk/.paddlex/official_models.
/home/skywalk/py310/lib/python3.10/site-packages/paddle/utils/cpp_extension/extension_utils.py:686: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md
  warnings.warn(warning_message)
Using official model (PP-OCRv4_mobile_rec), the model files will be be automatically downloaded and saved in /home/skywalk/.paddlex/official_models.
Connecting to https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/general_ocr_002.png ...
Downloading general_ocr_002.png ...
[==================================================] 100.00%
{'input_path': '/home/skywalk/.paddlex/predict_input/general_ocr_002.png', 'dt_polys': [array([[ 7, 14],
       [51, 14],
       [51, 29],
       [ 7, 29]], dtype=int16), array([[703,  14],
       [823,  14],
       [823,  59],
       [703,  59]], dtype=int16), array([[159,  26],
       [355,  24],
       [355,  70],
       [159,  72]], dtype=int16), array([[424,  25],
       [657,  20],
       [657,  57],
       [424,  61]], dtype=int16), array([[343, 107],
       [386, 107],
       [386, 127],
       [343, 127]], dtype=int16), array([[396, 105],
       [457, 103],
       [458, 125],
       [397, 127]], dtype=int16), array([[489, 103],
       [535, 103],
       [535, 126],
       [489, 126]], dtype=int16), array([[525, 104],
       [648, 101],
       [648, 122],
       [525, 125]], dtype=int16), array([[677,  98],
       [741,  95],
       [742, 120],
       [678, 124]], dtype=int16), array([[214, 109],
       [318, 107],
       [318, 129],
       [214, 131]], dtype=int16), array([[753, 100],
       [831,  97],
       [832, 115],
       [754, 119]], dtype=int16), array([[ 64, 113],
       [192, 109],
       [192, 130],
       [ 64, 133]], dtype=int16), array([[233, 137],
       [327, 135],
       [327, 160],
       [233, 162]], dtype=int16), array([[406, 135],
       [431, 135],
       [431, 159],
       [406, 159]], dtype=int16), array([[509, 129],
       [571, 129],
       [571, 159],
       [509, 159]], dtype=int16), array([[ 84, 141],
       [212, 139],
       [212, 161],
       [ 84, 163]], dtype=int16), array([[344, 177],
       [409, 174],
       [410, 196],
       [345, 198]], dtype=int16), array([[416, 176],
       [469, 176],
       [469, 194],
       [416, 194]], dtype=int16), array([[491, 176],
       [553, 176],
       [553, 195],
       [491, 195]], dtype=int16), array([[567, 175],
       [614, 175],
       [614, 194],
       [567, 194]], dtype=int16), array([[679, 170],
       [810, 167],
       [810, 189],
       [679, 192]], dtype=int16), array([[ 67, 182],
       [169, 178],
       [169, 200],
       [ 67, 203]], dtype=int16), array([[ 98, 209],
       [170, 206],
       [170, 228],
       [ 98, 230]], dtype=int16), array([[338, 219],
       [475, 214],
       [475, 236],
       [338, 240]], dtype=int16), array([[508, 216],
       [553, 216],
       [553, 235],
       [508, 235]], dtype=int16), array([[ 92, 229],
       [203, 229],
       [203, 251],
       [ 92, 251]], dtype=int16), array([[345, 240],
       [482, 238],
       [482, 259],
       [345, 261]], dtype=int16), array([[ 68, 251],
       [173, 251],
       [173, 272],
       [ 68, 272]], dtype=int16), array([[ 77, 278],
       [265, 273],
       [265, 298],
       [ 77, 302]], dtype=int16), array([[462, 298],
       [578, 295],
       [578, 316],
       [462, 320]], dtype=int16), array([[102, 314],
       [209, 310],
       [210, 336],
       [103, 340]], dtype=int16), array([[ 69, 345],
       [165, 342],
       [165, 365],
       [ 69, 367]], dtype=int16), array([[346, 349],
       [661, 346],
       [661, 368],
       [346, 370]], dtype=int16), array([[102, 459],
       [348, 455],
       [348, 475],
       [102, 480]], dtype=int16), array([[338, 455],
       [830, 444],
       [830, 463],
       [338, 473]], dtype=int16)], 'dt_scores': [0.8086473963830697, 0.7444834845268138, 0.7048532694664938, 0.8167863148375849, 0.8527043002268895, 0.80341476706128, 0.8344790145609061, 0.8201786745449452, 0.8037534924413309, 0.8418030630545272, 0.8281395105455075, 0.8436082237135579, 0.8980652274996248, 0.8509039952363526, 0.926031375976406, 0.917996154974153, 0.8356580269317107, 0.880335328903524, 0.786900038130219, 0.8448373590419963, 0.8538021008593104, 0.8094333203814897, 0.8155846152322913, 0.8009513868620355, 0.7908997998466479, 0.9064951564646333, 0.781499426792946, 0.8041485734460104, 0.8052928610838584, 0.7971443376064804, 0.8127219713134701, 0.8772702067806731, 0.8593806578727476, 0.8892553445879527, 0.7193662265720893], 'rec_text': ['88', 'PASS', '登机牌', 'BOARDING', '舱位', 'CLASS', '序号', 'SERIAL NO.', '座位号', '日期 DATE', 'SEAT NO', '航班 FLIGHT', '03DEC', 'W', '035', 'MU2379', '始发地', 'FROM', '登机口', 'GATE', '登机时间BDT', '目的地TO', '福州', 'TAIYUAN', 'G11', 'FUZHOU', '身份识别IDNO', '姓名NAME', 'ZHANGQIWEI', '票号TKTNO', '张祺伟', '票价FARE', 'ETKT7813699238489/1', '登机口于起飞前10分钟关闭', 'GATES CLOSE 1O MINUTESBEFOREDEPARTURE TIME'], 'rec_score': [0.2818991243839264, 0.9737589359283447, 0.9956169724464417, 0.9914350509643555, 0.999286413192749, 0.9870386123657227, 0.9988601803779602, 0.9191064834594727, 0.9967336654663086, 0.9261701703071594, 0.9249376654624939, 0.9562639594078064, 0.9878450632095337, 0.9664050936698914, 0.9987359046936035, 0.9978847503662109, 0.9977880120277405, 0.9939311742782593, 0.9992539882659912, 0.9932109713554382, 0.9979119896888733, 0.9743624925613403, 0.9977253675460815, 0.9913478493690491, 0.9793536067008972, 0.9940326809883118, 0.9943745732307434, 0.9927486777305603, 0.9915329217910767, 0.9926781058311462, 0.9977713227272034, 0.9842863082885742, 0.9945623278617859, 0.9975420236587524, 0.9551531672477722]}

下面就可以开始我们的AI之旅啦!

paddlex例子:时序预测

参考:时序预测产线 - PaddleX 文档

下载文件

!wget https://paddle-model-ecology.bj.bcebos.com/paddlex/ts/demo_ts/ts_fc.csv

开始预测:

from paddlex import create_pipeline

pipeline = create_pipeline(pipeline="ts_fc")

output = pipeline.predict("ts_fc.csv")
for res in output:
    res.print() ## 打印预测的结构化输出
    res.save_to_csv("./output/") ## 保存csv格式结果

预测成功:

{'input_path': 'ts_fc.csv', 'forecast':                            OT
date                         
2018-06-26 20:00:00  9.586130
2018-06-26 21:00:00  9.379762
2018-06-26 22:00:00  9.252276
2018-06-26 23:00:00  9.249993
2018-06-27 00:00:00  9.164998
...                       ...
2018-06-30 15:00:00  8.830339
2018-06-30 16:00:00  9.291553
2018-06-30 17:00:00  9.097667
2018-06-30 18:00:00  8.905429
2018-06-30 19:00:00  8.993793

[96 rows x 1 columns]}
The result has been saved in output/ts_fc.csv.

Windows10下的vscode使用远程Jupyter

vscode里面使用本地jupyter很简单,安装一个jupyter插件即可。

使用远程jupyter,则需要

首先进入viscode,安装官方jupyter插件

开始配置

安装好后,按Ctrl+Shift+P,或者按F1

然后键入:

Jupyter: Specify Jupyter Server for Connections

在出现的notebook右上角,点击kernel,选择远程kernel,

然后输入rul地址+token:

http://http://172.25.183.186/:8889/lab?token=8654db547811f9ac9240c96496e5a14195ba689ad799ef52

不过我目前还没有调通,每次输入地址都会变掉:

http://172.25.183.186:8889
变成
http://172.25.183.186/:8889

然后报错:啥啥forbidden

后来试出来了,需要输入rul地址,比如:

http://172.25.183.186:8889

然后要求输入密码的时候,输入token,然后就可以了。

但是第二次的时候,再输入token,验证就没通过。于是采用给jupyter设置密码的方法。

设置登录密码

给jupyter设置密码:

jupyter-server password
Enter password:
Verify password:
[JupyterPasswordApp] Wrote hashed password to /home/xxxx/.jupyter/jupyter_server_config.json

vscode设置

在vscode里按Ctrl+Shift+P,或者按F1

然后键入:

Jupyter: Specify Jupyter Server for Connections

在出现的notebook右上角,点击kernel,选择远程kernel,

然后输入rul地址,比如:

http://172.25.183.186:8889

输入密码,输入刚才使用jupyter-server password 设置的密码,通过后,就可以使用远程的jupyter啦!

相关推荐
匹马夕阳1 小时前
安装Anaconda搭建Python环境,并使用VSCode作为IDE运行Python脚本
ide·vscode·python
jerry-891 小时前
Windows系统下FFmpeg4.4的环境搭建(二)
windows
dazhong20122 小时前
Windows 环境配置 HTTPS 服务实战
windows·网络协议·https
布兰妮甜2 小时前
VSCode 插件全解析:解锁编码新维度
ide·vscode·编辑器
小远披荆斩棘2 小时前
Mac中配置vscode(第一期:python开发)
vscode·python·macos
ad转化器2 小时前
VSCode设置ctrl或alt+mouse(left)跳转
ide·vscode·编辑器
赔罪3 小时前
HTML-文本标签
前端·vscode·html·webstorm
彳亍2615 小时前
前端笔记:vscode Vue nodejs npm
前端·vscode
cv小白菜6 小时前
容器化部署算法服务技术文档
python·ubuntu·docker
Camllia376 小时前
游戏无法运行、图形显示错误、视频播放卡顿、音频播放无声等等电脑问题要怎么轻松解决?使用修复工具推荐!
windows·经验分享·游戏·电脑