0%

jupyterlab 安装 extension 出现 build 错误:codec error 解决方案

There is a title.

文首先放参考链接:https://www.cnblogs.com/banshaohuan/p/13652143.html

在安装一个自动补全的插件(Kite) 后,Jupyter 提示需要重新 build。

在命令行输入 jupyter lab build 后,出现报错信息如下。错误原因主要是 Windows 的编码问题。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[LabBuildApp] JupyterLab 2.2.8
[LabBuildApp] Building in C:\Users\xxx\AppData\Roaming\Python\share\jupyter\lab
[LabBuildApp] Building jupyterlab assets (build:prod:minimize)
\Exception in thread Thread-7:
Traceback (most recent call last):
File "c:\program files\python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "c:\program files\python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "c:\program files\python38\lib\subprocess.py", line 1366, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 281: illegal multibyte sequence
Build failed.
Troubleshooting: If the build failed due to an out-of-memory error, you
may be able to fix it by disabling the `dev_build` and/or `minimize` options.

If you are building via the `jupyter lab build` command, you can disable
these options like so:

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

You can also disable these options for all JupyterLab builds by adding these
lines to a Jupyter config file named `jupyter_config.py`:

c.LabBuildApp.minimize = False
c.LabBuildApp.dev_build = False

If you don't already have a `jupyter_config.py` file, you can create one by
adding a blank file of that name to any of the Jupyter config directories.
The config directories can be listed by running:

jupyter --paths

Explanation:

- `dev-build`: This option controls whether a `dev` or a more streamlined
`production` build is used. This option will default to `False` (ie the
`production` build) for most users. However, if you have any labextensions
installed from local files, this option will instead default to `True`.
Explicitly setting `dev-build` to `False` will ensure that the `production`
build is used in all circumstances.

- `minimize`: This option controls whether your JS bundle is minified
during the Webpack build, which helps to improve JupyterLab's overall
performance. However, the minifier plugin used by Webpack is very memory
intensive, so turning it off may help the build finish successfully in
low-memory environments.

An error occured.
IndexError: list index out of range
See the log file for details: C:\Users\xxx\AppData\Local\Temp\jupyterlab-debug-uqrv_41g.log

最初我判断问题出在 Powershell 上,因为 Windows 默认编码是 gdk ,所以经常出现问题,搜了一下改 Powershell 编码的方法:https://blog.csdn.net/x356982611/article/details/80285930。问题没有解决。

根据解决方案,我们直接去 Jupyter Lab 的安装路径,修改 Python 源码即可。

img

新增一行编码即可解决问题。重新执行 build 得到输出。

1
2
3
PS C:\Users\xxx> jupyter lab build                                                                                       [LabBuildApp] JupyterLab 2.2.8
[LabBuildApp] Building in C:\Users\xxx\AppData\Roaming\Python\share\jupyter\lab
[LabBuildApp] Building jupyterlab assets (build:prod:minimize)