ILLUSTRATION

jupyter lab build报错

因为jupyter notebook的代码补全不好使, 打算装一个kite

在jupyter lab安装好了kite后, 需要编译(build)

jupyter lab build报错RuntimeError: npm dependencies failed to install

[LabBuildApp] JupyterLab 3.0.10
[LabBuildApp] Building in /home/hjy/.local/share/jupyter/lab
[LabBuildApp] Building jupyterlab assets (production, minimized)
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 (i.e., 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.
    RuntimeError: npm dependencies failed to install
    See the log file for details: /tmp/jupyterlab-debug-fz1wbvsf.log

环境/版本

  • 操作系统: ubuntu 18.04 LTS
  • python-3.6.9
  • jupyter-1.0.0
  • jupyterlab-3.0.10
  • jupyterlab-kite-2.0.2
  • node-v14.16.0
  • npm-7.6.3
  • yarn-1.22.10

报错日志

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
[LabBuildApp] Building in /home/hjy/.local/share/jupyter/lab
[LabBuildApp] Node v14.16.0

[LabBuildApp] Yarn configuration loaded.
[LabBuildApp] Building jupyterlab assets (production, minimized)
[LabBuildApp] > node /home/hjy/.local/lib/python3.6/site-packages/jupyterlab/staging/yarn.js install --non-interactive
[LabBuildApp] yarn install v1.21.1
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
error An unexpected error occurred: "https://registry.npm.taobao.org/@jupyterlab/application/-/application-3.0.6.tgz: Request failed \"404 Not Found\"".
info If you think this is a bug, please open a bug report with the information provided in "/home/hjy/.local/share/jupyter/lab/staging/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

[LabBuildApp] npm dependencies failed to install
[LabBuildApp] Traceback (most recent call last):

[LabBuildApp] File "/home/hjy/.local/lib/python3.6/site-packages/jupyterlab/debuglog.py", line 47, in debug_logging
yield

[LabBuildApp] File "/home/hjy/.local/lib/python3.6/site-packages/jupyterlab/labapp.py", line 166, in start
raise e

[LabBuildApp] File "/home/hjy/.local/lib/python3.6/site-packages/jupyterlab/labapp.py", line 163, in start
app_options=app_options, production = production, minimize=self.minimize)

[LabBuildApp] File "/home/hjy/.local/lib/python3.6/site-packages/jupyterlab/commands.py", line 470, in build
production=production, minimize=minimize, clean_staging=clean_staging)

[LabBuildApp] File "/home/hjy/.local/lib/python3.6/site-packages/jupyterlab/commands.py", line 669, in build
raise RuntimeError(msg)

[LabBuildApp] RuntimeError: npm dependencies failed to install

[LabBuildApp] Exiting application: JupyterLab

可以看到这样一段

1
"https://registry.npm.taobao.org/@jupyterlab/application/-/application-3.0.6.tgz: Request failed \"404 Not Found\"".

用浏览器打开也发现:

image-20210317153828545

无法访问, 看来是taobao源出现了问题, 现在需要换源

解决

npm/yarn的源网上有很多, 这里以最不好找的官方源为例(没错, 官方默认的源反而最难找)

1
2
3
sudo yarn config set registry https://registry.yarnpkg.com --global
sudo yarn config set disturl https://registry.yarnpkg.com --global
sudo npm config set registry https://registry.yarnpkg.com --global

查看yarn版本信息:

1
yarn config list 

显示:

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
yarn config v1.22.10
info yarn config
{
'version-tag-prefix': 'v',
'version-git-tag': true,
'version-commit-hooks': true,
'version-git-sign': false,
'version-git-message': 'v%s',
'init-version': '1.0.0',
'init-license': 'MIT',
'save-prefix': '^',
'bin-links': true,
'ignore-scripts': false,
'ignore-optional': false,
registry: 'https://registry.yarnpkg.com',
'strict-ssl': true,
'user-agent': 'yarn/1.22.10 npm/? node/v14.16.0 linux x64',
disturl: 'https://registry.yarnpkg.com/dist',
lastUpdateCheck: 1615890770522
}
info npm config
{
registry: 'https://registry.yarnpkg.com/'
}
Done in 0.03s.

找到安装yarn的地方

1
2
3
4
whereis yarn
ll /usr/bin/yarn
cd /usr/lib/node_modules/yarn/
ls

image-20210317161011766

删掉node_modulesyarn.lock, 重新下载

1
2
3
sudo rm yarn.lock
sudo rm -rf node_modules/
sudo yarn install

image-20210317161839816

同样, 再找到jupyter lab在哪儿

1
2
3
4
whereis jupyter
cd /home/hjy/.local/
cd share/jupyter/lab
cd staging/ && ls

image-20210317162536517

重复上面工作, 删除后再下载:

1
2
3
rm yarn.lock
rm -rf node_modules/
node yarn.js install

image-20210317162654410

出现了一堆warning, 不用管

然后build:

1
jupyter lab build

image-20210317162838425

没报错, 成功解决