JypyterLab学习之二(JypyterLab编译运行)

一、git clone代码

git clone XXX

创建环境

conda创建python环境

conda create -n jupyterlab python=3.8
conda activate jupyterlab

conda创建node环境

conda search nodejs # 搜索conda下的nodejs版本。
conda install nodejs=16.13.1 -c conda-forge

二、安装python依赖

官网给的命令是:

pip install -e .

这个命令会报各种错,可以换成下面这个:

pip install -v -e .

如果执行报错,先执行

jupyter lab clean
jupyter lab build --minimize=False --dev-build=False

如果报下面错误,需要手动执行:

npm install -g node-gyp

报错信息部分截图:

  Warning: Missing input files:
  C:\GTK\bin\libglib-2.0-0.dll
  C:\GTK\bin\libgobject-2.0-0.dll
  C:\GTK\bin\libgmodule-2.0-0.dll
  C:\GTK\bin\libgthread-2.0-0.dll
  C:\GTK\bin\libpng14-14.dll
  C:\GTK\bin\zlib1.dll
  C:\GTK\bin\libfontconfig-1.dll
  C:\GTK\bin\libfreetype-6.dll
  C:\GTK\bin\libpangoft2-1.0-0.dll
  C:\GTK\bin\libpangocairo-1.0-0.dll
  C:\GTK\bin\libexpat-1.dll
  C:\GTK\bin\libcairo-2.dll
  C:\GTK\bin\libintl-8.dll
  C:\GTK\bin\libpangowin32-1.0-0.dll
  C:\GTK\bin\libpango-1.0-0.dll
  gyp info ok
  gyp info it worked if it ends with ok
  gyp info using node-gyp@9.1.0
  gyp info using node@16.13.1 | win32 | x64
  gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe
  gyp info spawn args [
  gyp info spawn args   'build/binding.sln',
  gyp info spawn args   '/clp:Verbosity=minimal',
  gyp info spawn args   '/nologo',
  gyp info spawn args   '/p:Configuration=Release;Platform=x64'
  gyp info spawn args ]
  鍦ㄦ\xadよВ鍐虫柟妗堜腑涓\x80娆$敓鎴愪竴涓\xaa椤圭洰銆傝嫢瑕佸惎鐢ㄥ苟琛岀敓鎴愶紝璇锋坊鍔犫\x80\x9c-m鈥濆紑鍏炽\x80\x82
    Backend.cc
  E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas\src\backend\Backend.h(3,10): fatal  error C1083: 鏃犳硶鎵撳紑鍖呮嫭鏂囦欢: 鈥渃airo.h鈥\x9d: No such file or directory [E:\Workspace\Python\M
BSHQQB\Game-Ai\jupyterlab\node_modules\canvas\build\canvas.vcxproj]
  gyp ERR! build error
  gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
  gyp ERR! stack     at ChildProcess.onExit (E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\node-gyp\lib\build.js:201:23)
  gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
  gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
  gyp ERR! System Windows_NT 10.0.22000
  gyp ERR! command "C:\\Users\\mbshq\\.conda\\envs\\jupyterlab\\node.exe" "E:\\Workspace\\Python\\MBSHQQB\\Game-Ai\\jupyterlab\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--update-
binary" "--module=E:\\Workspace\\Python\\MBSHQQB\\Game-Ai\\jupyterlab\\node_modules\\canvas\\build\\Release\\canvas.node" "--module_name=canvas" "--module_path=E:\\Workspace\\Python\\MBSHQQB\\Game-Ai\\jupyterla
b\\node_modules\\canvas\\build\\Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
  gyp ERR! cwd E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas
  gyp ERR! node -v v16.13.1
  gyp ERR! node-gyp -v v9.1.0
  gyp ERR! not ok
  node-pre-gyp ERR! build error
  node-pre-gyp ERR! stack Error: Failed to execute 'C:\Users\mbshq\.conda\envs\jupyterlab\node.exe E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build
--update-binary --module=E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas\build\Release\canvas.node --module_name=canvas --module_path=E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modul
es\canvas\build\Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
  node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\@mapbox\node-pre-gyp\lib\util\compile.js:89:23)
  node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:390:28)
  node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
  node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
  node-pre-gyp ERR! System Windows_NT 10.0.22000
  node-pre-gyp ERR! command "C:\\Users\\mbshq\\.conda\\envs\\jupyterlab\\node.exe" "E:\\Workspace\\Python\\MBSHQQB\\Game-Ai\\jupyterlab\\node_modules\\@mapbox\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fall
back-to-build" "--update-binary"
  node-pre-gyp ERR! cwd E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas
  node-pre-gyp ERR! node -v v16.13.1
  node-pre-gyp ERR! node-pre-gyp -v v1.0.9
  node-pre-gyp ERR! not ok
  Failed to execute 'C:\Users\mbshq\.conda\envs\jupyterlab\node.exe E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --update-binary --module=E:\Wor
kspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas\build\Release\canvas.node --module_name=canvas --module_path=E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\node_modules\canvas\build\Release --napi_
version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
  info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
  Traceback (most recent call last):
    File "C:\Users\mbshq\.conda\envs\jupyterlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 165, in prepare_metadata_for_build_editable
      hook = backend.prepare_metadata_for_build_editable
  AttributeError: module 'hatchling.build' has no attribute 'prepare_metadata_for_build_editable'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "C:\Users\mbshq\.conda\envs\jupyterlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 351, in <module>
      main()
    File "C:\Users\mbshq\.conda\envs\jupyterlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 333, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Users\mbshq\.conda\envs\jupyterlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py", line 174, in prepare_metadata_for_build_editable
      whl_basename = build_hook(metadata_directory, config_settings)
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\overlay\Lib\site-packages\hatchling\build.py", line 61, in build_editable
      return os.path.basename(next(builder.build(wheel_directory, ['editable'])))
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\overlay\Lib\site-packages\hatchling\builders\plugin\interface.py", line 136, in build
      build_hook.initialize(version, build_data)
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\normal\Lib\site-packages\hatch_jupyter_builder\plugin.py", line 83, in initialize
      raise e
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\normal\Lib\site-packages\hatch_jupyter_builder\plugin.py", line 78, in initialize
      build_func(self.target_name, version, **build_kwargs)
    File "E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab\buildapi.py", line 21, in builder
      npm_builder(target_name, version, *args, **kwargs)
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\normal\Lib\site-packages\hatch_jupyter_builder\utils.py", line 114, in npm_builder
      run(npm_cmd + ["install"], cwd=str(abs_path))
    File "C:\Users\mbshq\AppData\Local\Temp\pip-build-env-8ga4e9_1\normal\Lib\site-packages\hatch_jupyter_builder\utils.py", line 227, in run
      return subprocess.check_call(cmd, **kwargs)
    File "C:\Users\mbshq\.conda\envs\jupyterlab\lib\subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['C:\\Users\\mbshq\\.conda\\envs\\jupyterlab\\node.EXE', 'jupyterlab/staging/yarn.js', 'install']' returned non-zero exit status 1.
  error: subprocess-exited-with-error

  × Preparing editable metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: 'C:\Users\mbshq\.conda\envs\jupyterlab\python.exe' 'C:\Users\mbshq\.conda\envs\jupyterlab\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' prepare_metadata_for_build_editable 'C:\
Users\mbshq\AppData\Local\Temp\tmpmspwhs0a'
  cwd: E:\Workspace\Python\MBSHQQB\Game-Ai\jupyterlab
  Preparing editable metadata (pyproject.toml) ... error
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

三、安装前端依赖

jlpm install

四、编译后端

jupyter lab clean
jupyter lab build --minimize=False --dev-build=False

五、编译前端

jlpm run build

(jupyterlab) E:\Workspace\GitHub\JupyterLab\jupyterlab>jlpm install
yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "@typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-de
v || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
warning " > typedoc@0.22.18" has unmet peer dependency "typescript@4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x || 4.5.x || 4.6.x || 4.7.x".
warning "workspace-aggregator-bde6c1fb-4ee9-4979-a696-779288ee8d02 > @jupyterlab/extensionmanager > react-paginate@6.5.0" has incorrect peer dependency
"react@^16.0.0".
warning "workspace-aggregator-bde6c1fb-4ee9-4979-a696-779288ee8d02 > @jupyterlab/json-extension > react-highlighter@0.4.3" has incorrect peer dependency
 "react@^0.14.0 || ^15.0.0 || ^16.0.0".
warning "workspace-aggregator-bde6c1fb-4ee9-4979-a696-779288ee8d02 > @jupyterlab/vdom > @nteract/transform-vdom@4.0.16-alpha.0" has incorrect peer depen
dency "react@^16.3.2".
warning "workspace-aggregator-bde6c1fb-4ee9-4979-a696-779288ee8d02 > @jupyterlab/buildutils > verdaccio > clipanion@3.1.0" has unmet peer dependency "ty
panion@*".
warning Workspaces can only be enabled in private projects.
warning Workspaces can only be enabled in private projects.
[4/4] Building fresh packages...
$ node scripts/ensure-buildutils.js

> @jupyterlab/buildutils@4.0.0-alpha.16 clean
> rimraf lib && rimraf tsconfig.tsbuildinfo


> @jupyterlab/buildutils@4.0.0-alpha.16 build
> tsc && cd template && npm run build


> @jupyterlab/template@4.0.0-alpha.16 build
> tsc -b


> @jupyterlab/builder@4.0.0-alpha.16 clean
> rimraf lib && rimraf tsconfig.tsbuildinfo


> @jupyterlab/builder@4.0.0-alpha.16 build
> tsc

Done in 117.22s.

(jupyterlab) E:\Workspace\GitHub\JupyterLab\jupyterlab>jupyter lab clean
[LabCleanApp] Cleaning D:\SoftWare\anaconda3\share\jupyter\lab...
[LabCleanApp] staging not present, skipping...
[LabCleanApp] Success!

(jupyterlab) E:\Workspace\GitHub\JupyterLab\jupyterlab>jupyter lab build --minimize=False --dev-build=False
[LabBuildApp] JupyterLab 2.2.6
[LabBuildApp] Building in D:\SoftWare\anaconda3\share\jupyter\lab
[LabBuildApp] Building jupyterlab assets (build:prod)
\
(jupyterlab) E:\Workspace\GitHub\JupyterLab\jupyterlab>jlpm run build
yarn run v1.22.19
$ npm run build:dev

> @jupyterlab/repo-top@0.0.1 build:dev
> npm run integrity && npm run build:all && cd dev_mode && npm run build


> @jupyterlab/repo-top@0.0.1 integrity
> node scripts/ensure-buildutils.js && node buildutils/lib/ensure-repo.js


> @jupyterlab/buildutils@4.0.0-alpha.16 clean
> rimraf lib && rimraf tsconfig.tsbuildinfo


> @jupyterlab/buildutils@4.0.0-alpha.16 build
> tsc && cd template && npm run build


> @jupyterlab/template@4.0.0-alpha.16 build
> tsc -b


> @jupyterlab/builder@4.0.0-alpha.16 clean
> rimraf lib && rimraf tsconfig.tsbuildinfo


> @jupyterlab/builder@4.0.0-alpha.16 build
> tsc

Error: Command failed: hatchling version
'hatchling' �����ڲ����ⲿ���Ҳ���ǿ����еij���
�����������

    at checkExecSyncError (node:child_process:826:11)
    at Object.execSync (node:child_process:900:15)
    at run (E:\Workspace\GitHub\JupyterLab\jupyterlab\buildutils\lib\utils.js:251:43)
    at Object.getPythonVersion (E:\Workspace\GitHub\JupyterLab\jupyterlab\buildutils\lib\utils.js:197:19)
    at ensureIntegrity (E:\Workspace\GitHub\JupyterLab\jupyterlab\buildutils\lib\ensure-repo.js:775:24)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 1,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 27 68 61 74 63 68 6c 69 6e 67 27 20 b2 bb ca c7 c4 da b2 bf bb f2 cd e2 b2 bf c3 fc c1 ee a3 ac d2 b2 b2 bb ca c7 bf c9 d4 cb d0 d0 b5 c4 b3
 cc d0 f2 ... 18 more bytes>
  ],
  pid: 20296,
  stdout: <Buffer >,
  stderr: <Buffer 27 68 61 74 63 68 6c 69 6e 67 27 20 b2 bb ca c7 c4 da b2 bf bb f2 cd e2 b2 bf c3 fc c1 ee a3 ac d2 b2 b2 bb ca c7 bf c9 d4 cb d0 d0 b5
 c4 b3 cc d0 f2 ... 18 more bytes>
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

需要安装hatch打包工具,可执行下面命令进行安装:

conda install -c conda-forge hatch
六、开发者模式启动jupyter lab

jupyter lab --dev-mode
jupyter lab --dev-mode --watch
jupyter lab --dev-mode --watch --extensions-in-dev-mode

启动如果报下面错误:

[W 2022-12-18 18:45:04.782 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7/channels?session_id=7cbd3ce0-b410-4d00-8813-fad5e84ef3e8 (::1): Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a00
5bf0489b7
[W 2022-12-18 18:45:04.783 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7/channels?session_id=7cbd3ce0-b410-4d00-8813-fad5e84ef3e8 (bd5e8e9f2edb424b903fc6efc619c313@::1) 2.01ms referer=Non
e
[W 2022-12-18 18:45:04.785 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7?1671360304784 (::1): Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a005bf0489b7
[W 2022-12-18 18:45:04.785 ServerApp] wrote error: 'Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a005bf0489b7'
[W 2022-12-18 18:45:04.787 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7?1671360304784 (bd5e8e9f2edb424b903fc6efc619c313@::1) 1.18ms referer=http://localhost:8888/lab?
[W 2022-12-18 18:45:05.882 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7/channels?session_id=5040ab3d-b970-4d49-ba5a-b1ad03472ff9 (::1): Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a00
5bf0489b7
[W 2022-12-18 18:45:05.884 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7/channels?session_id=5040ab3d-b970-4d49-ba5a-b1ad03472ff9 (bd5e8e9f2edb424b903fc6efc619c313@::1) 2.76ms referer=Non
e
[W 2022-12-18 18:45:05.885 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7?1671360305884 (::1): Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a005bf0489b7
[W 2022-12-18 18:45:05.885 ServerApp] wrote error: 'Kernel does not exist: 10edb0fd-3f46-423c-aa7e-a005bf0489b7'
[W 2022-12-18 18:45:05.886 ServerApp] 404 GET /api/kernels/10edb0fd-3f46-423c-aa7e-a005bf0489b7?1671360305884 (bd5e8e9f2edb424b903fc6efc619c313@::1) 0.87ms referer=http://localhost:8888/lab?
[I 2022-12-18 18:45:07.578 ServerApp] AsyncIOLoopKernelRestarter: restarting kernel (4/5), new random ports
Traceback (most recent call last):
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\ipykernel\__init__.py", line 5, in <module>
    from .connect import *  # noqa
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\ipykernel\connect.py", line 11, in <module>
    import jupyter_client
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\jupyter_client\__init__.py", line 8, in <module>
    from .asynchronous import AsyncKernelClient  # noqa
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\jupyter_client\asynchronous\__init__.py", line 1, in <module>
    from .client import AsyncKernelClient  # noqa
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\jupyter_client\asynchronous\client.py", line 6, in <module>
    from jupyter_client.channels import HBChannel
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\jupyter_client\channels.py", line 12, in <module>
    import zmq.asyncio
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\zmq\__init__.py", line 103, in <module>
    from zmq import backend
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\zmq\backend\__init__.py", line 31, in <module>
    raise original_error from None
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\zmq\backend\__init__.py", line 26, in <module>
    _ns = select_backend(first)
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\zmq\backend\select.py", line 31, in select_backend
    mod = import_module(name)
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\mbshq\.conda\envs\jupyterlab-extension-examples\lib\site-packages\zmq\backend\cython\__init__.py", line 6, in <module>
    from . import (
ImportError: DLL load failed while importing _device: 找不到指定的模块。

上面是因为ipykernel有问题,需要先查看ipykernel的位置:

jupyter kernelspec list

>Available kernels:
  python3    C:\Users\mbshq\AppData\Roaming\jupyter\kernels\python3

打开C:\Users\mbshq\AppData\Roaming\jupyter\runtime,删除runtime文件夹下的内容,重新启动即可。

七、独立运行example

将目录切换到examples/下执行:

jlpm
run build:examples

将目录切换到具体的example目录下执行:

python main.py

debug方法:https://jupyterlab.readthedocs.io/en/stable/developer/contributing.html#build-and-run-the-stand-alone-examples

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值