Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed May 20, 2023
1 parent c36eb95 commit 77c92dd
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 53 deletions.
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

假如你有一个远端仓库(比如 Github),使用 [克隆](https://mybinder.org/v2/gh/Hi-Windom/jupyter-binder/HEAD?urlpath=lab/tree/loader.ipynb) 链接;如果只是想运行单个文件,直接从本地上传是最好的选择,也可以从 URL 打开。

~~任意 ipynb 公开仓库可 [在线生成链接](https://hub.jupyter.org/nbgitpuller/link?tab=binder) ,而无需提供额外配置~~(暂不可用,故障排查中)

基于 Binder 实现,可以在 `Dockerfile``FROM soltus/jupyter-binder:latest` 开始构建自定义的环境镜像

更多内容参考 [binder.ipynb](https://github.com/Hi-Windom/jupyter-binder/blob/main/binder.ipynb)
Expand All @@ -41,32 +39,7 @@
>
> 非 Python 内核需自行安装
前置准备:

1. `conda info -e` 命令应对输出而不是报错

在 README.md 文件所在路径打开终端,运行以下命令:(应当使用 PowerShell 而不是 CMD 以避免意外发生)

```powershell
conda create -n lab python=3.10
conda actiavte lab
```

```powershell
pip install pip-tools -i https://mirrors.tencent.com/pypi/simple
```

```powershell
pip-sync win.requirements.txt --pip-args "--quiet --retries 10 --timeout 30"
```

```powershell
jupyter lab --port='6969' --ip='*' --no-browser --allow-root --notebook-dir='D:\\TEMP\\jlab\\notebook'
```

--notebook-dir 传参因人而异,不出意外的话复苏成功。在终端 CTRL + 单击链接或者手动打开浏览器访问 [http://127.0.0.1:6969/lab](http://127.0.0.1:6969/lab) ,时间交给你了

可以使用 `pip list --outdated` 检查过时的包
参考 [index.ipynb](https://github.com/Hi-Windom/jupyter-binder/blob/main/index.ipynb)

# 初始化工作

Expand Down
156 changes: 150 additions & 6 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,59 @@
"<p><span style=\"color: #169179;\">根据 README.md 复苏说明,随时随地部署 Jupyter Lab ,就如同安装普通软件一样简单</span></p>"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "bd676544",
"metadata": {},
"source": [
"硬盘I/O性能会显著影响 jupyter 运行性能!\n",
"假如 conda 安装位置所在硬盘I/O性能较差,可选的步骤是指定新虚拟环境的路径 `conda create -p G:\\\\BDC\\\\conda\\\\lab python=3.10` ,其中 `lab` 是虚拟环境名称,通过指定路径方式创建的虚拟环境与普通虚拟环境不同,使用 `conda activate G:\\\\BDC\\\\conda\\\\lab` 激活而不是 `conda activate lab`"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "3141eaea",
"metadata": {},
"source": [
"使用 vscode 重新打开本 notebook 文件,切换虚拟环境为上面创建的虚拟环境,运行下面的命令\n",
"\n",
"如果 vscode 提示需要 ipykernel 包,点击【安装】选项,会自动安装。如果是指定路径创建的虚拟环境,ipykernel 包可能无法由 vscode 成功安装,解决办法:在终端环境激活上面创建的虚拟环境,使用 `pip install ipykernel` 安装 ipykernel 包,然后执行 `python -m ipykernel install --user --name=lab` 注册内核即可(特别说明:--name=lab 中的 lab 并非必须和虚拟环境名称一致)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "acaff651-0be6-41d2-b41a-0ea552b813fa",
"metadata": {},
"outputs": [],
"source": [
"# %pip install pip-tools -i https://mirrors.tencent.com/pypi/simple"
"# 已安装则不需要重复运行此命令\n",
"%pip install pip-tools -i https://mirrors.tencent.com/pypi/simple"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "13189ef6",
"metadata": {},
"source": [
"### 备份/恢复 二选一"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "30e2c72a",
"metadata": {},
"source": [
"### 生成依赖清单"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "208ebefc-053d-486d-af30-3d95e3eee16f",
"metadata": {
"execution": {
Expand All @@ -106,12 +146,24 @@
"source": [
"# 生成 windows AMD64平台的依赖清单\n",
"# win.requirements.in 的 UTF-8 编码请不要更改,不要在里面写入中文\n",
"# 运行前,检查所有已安装包的可执行文件是否均未在运行(例如 jupyter),避免占用或锁定导致的报错。同时也请注意:运行该命令会覆盖当前环境已安装的包(可在 win.requirements.in 锁版本)\n",
"# 运行前,检查所有已安装包的可执行文件是否均未在运行(例如 jupyter),避免占用或锁定导致的报错。\n",
"# 使用的源会影响是否找到所有 win.requirements.in 中列出的包(主要是指定了版本范围的),这是由于有些镜像收录不全或者版本更新延后,此时如果网络允许可以使用官方 PyPi 源 -i https://pypi.org/simple\n",
"# 一般情况下推荐使用腾讯云镜像加速 -i https://mirrors.tencent.com/pypi/simple\n",
"# 特别注意:下面的命令只有在本 notebook 文件在 vscode 中打开并选择了正确的虚拟环境下才可以直接执行,其他情况需要作出适当修改\n",
"!python -m piptools compile --quiet --upgrade --resolver=backtracking win.requirements.in --output-file win.requirements.txt -i https://mirrors.tencent.com/pypi/simple"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "59d848f9",
"metadata": {},
"source": [
"### 根据依赖清单安装包\n",
"\n",
"> 可使用 `pip list` 检查已安装的包, `pip list --outdated` 检查过时的包"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -121,7 +173,99 @@
},
"outputs": [],
"source": [
"!pip-sync win.requirements.txt --pip-args \"--quiet --retries 10 --timeout 30\""
"!pip-sync win.requirements.txt --pip-args \"--quiet --retries 10 --timeout 30 --index-url https://mirrors.tencent.com/pypi/simple\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "e0f00f71",
"metadata": {},
"source": [
"### 启动 jupyter lab"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "0de3c578",
"metadata": {},
"source": [
"在 PowerShell 终端运行下面的命令\n",
"\n",
"```powershell\n",
"jupyter lab --port='6969' --ip='*' --no-browser --allow-root --notebook-dir='D:\\\\TEMP\\\\jlab\\\\notebook'\n",
"```\n",
"\n",
"--notebook-dir 传参因人而异,不出意外的话复苏成功。在终端 CTRL + 单击链接或者手动打开浏览器访问 [http://127.0.0.1:6969/lab](http://127.0.0.1:6969/lab) ,时间交给你了\n",
"\n",
"或者,直接运行下面的代码块 FH92Y,然后手动打开浏览器访问 [http://127.0.0.1:6969/lab](http://127.0.0.1:6969/lab)。"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e047a3f1",
"metadata": {},
"outputs": [],
"source": [
"# 代码块 FH92Y\n",
"!jupyter lab --port=6969 --ip=* --no-browser --allow-root --notebook-dir=\"D:\\\\TEMP\\\\jlab\\\\notebook\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "6afd381f",
"metadata": {},
"source": [
"并不推荐直接运行上面代码块 FH92Y 这种方式,仅供测试使用,且需要 `netstat -ano | findstr :6969` 配合 `taskkill /f /pid` 手动结束进程。"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "abddfb47",
"metadata": {},
"source": [
"最后,可以通过下面的 C++ 代码构建一个可执行程序,只需要双击该程序即可快速运行 jupyter lab,也可以完成集成到其他软件,加入开机自启等操作\n",
"\n",
"注意事项:\n",
"\n",
"1. `conda activate lab` 可能需要根据前面的操作调整为 `conda activate G:\\\\BDC\\\\conda\\\\lab`\n",
"2. --notebook-dir 传参修改为正确的路径\n",
"\n",
"```cpp\n",
"#include <stdlib.h>\n",
"#include <Windows.h>\n",
"#include <shellapi.h>\n",
"#include <WinUser.h>\n",
"#pragma comment( linker, \"/subsystem:\\\"windows\\\" /entry:\\\"mainCRTStartup\\\"\" ) // 设置入口地址,隐藏控制台窗口\n",
"\n",
"using namespace std;\n",
"\n",
"int main()\n",
"{\n",
" // 如果 python 是 64位的,则生成对应的 x64 (64位) 程序\n",
" ShellExecute(NULL, L\"open\", L\"powershell\", L\"conda activate lab;jupyter lab --port='6969' --ip='*' --no-browser --allow-root --notebook-dir='D:\\\\TEMP\\\\jlab\\\\notebook'\", NULL, SW_SHOWMINNOACTIVE);\n",
" // 循环检测本地端口连通性,成功则自动打开指定链接。一般用不上\n",
" /*ShellExecute(NULL, L\"open\", L\"powershell\", L\"do{$ff=Test-NetConnection 127.0.0.1 -p 6969;\\\n",
"if($ff.TcpTestSucceeded -eq 'True'){start http://127.0.0.1:6969/lab}}until($ff.TcpTestSucceeded -eq 'False')\", NULL, SW_HIDE);*/\n",
"}\n",
"\n",
"/* 最后的那个参数,为窗口指定可视性方面的一个命令。 请用下述任何一个常数\n",
"* SW_HIDE 隐藏窗口,活动状态给令一个窗口\n",
"* SW_MINIMIZE 最小化窗口,活动状态给令一个窗口\n",
"* SW_RESTORE 用原来的大小和位置显示一个窗口,同时令其进入活动状态\n",
"* SW_SHOW 用当前的大小和位置显示一个窗口,同时令其进入活动状态\n",
"* SW_SHOWMAXIMIZED 最大化窗口,并将其激活\n",
"* SW_SHOWMINIMIZED 最小化窗口,并将其激活\n",
"* SW_SHOWMINNOACTIVE 最小化一个窗口,同时不改变活动窗口\n",
"* SW_SHOWNA 用当前的大小和位置显示一个窗口,不改变活动窗口\n",
"* SW_SHOWNOACTIVATE 用最近的大小和位置\n",
"* SW_SHOWNORMAL 正常显示\n",
"*/\n",
"```"
]
},
{
Expand All @@ -143,7 +287,7 @@
"# REF https://nbdime.readthedocs.io/en/latest/\n",
"# 激活差异对比工具\n",
"# 对于 Binder 或者 docker ,这一步不需要手动执行\n",
"!nbdime config-git --enable --global"
"%nbdime config-git --enable --global"
]
},
{
Expand Down Expand Up @@ -190,7 +334,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.10.11"
},
"vscode": {
"interpreter": {
Expand Down
21 changes: 2 additions & 19 deletions win.requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --index-url=https://mirrors.tencent.com/pypi/simple --output-file=win.requirements.txt --resolver=backtracking win.requirements.in
Expand Down Expand Up @@ -182,16 +182,6 @@ idna==3.4
# requests
# tldextract
# yarl
importlib-metadata==6.6.0
# via
# flask
# jupyter-client
# jupyter-lsp
# jupyter-ydoc
# jupyterlab-server
# nbconvert
importlib-resources==5.12.0
# via matplotlib
incremental==22.10.0
# via twisted
ipycytoscape==1.3.3
Expand Down Expand Up @@ -340,7 +330,7 @@ jupyterlab-execute-time==2.3.1
# via -r win.requirements.in
jupyterlab-git==0.41.0
# via -r win.requirements.in
jupyterlab-language-pack-zh-cn==3.6.post2
jupyterlab-language-pack-zh-cn==3.6.post1
# via -r win.requirements.in
jupyterlab-lsp==4.1.0
# via -r win.requirements.in
Expand Down Expand Up @@ -725,12 +715,9 @@ twisted-iocpsupport==1.0.3
# via twisted
typing-extensions==4.5.0
# via
# aioitertools
# altair
# ipython
# pandasgui
# pydantic
# starlette
# twisted
tzdata==2023.3
# via pandas
Expand Down Expand Up @@ -779,10 +766,6 @@ yarl==1.9.2
# via aiohttp
ypy-websocket==0.8.2
# via jupyter-server-ydoc
zipp==3.15.0
# via
# importlib-metadata
# importlib-resources
zope-interface==6.0
# via
# scrapy
Expand Down

0 comments on commit 77c92dd

Please sign in to comment.