Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 jupyter lab 安装 toc 后无法在侧边栏显示的问题 #211

Closed
Rick-Zo opened this issue Aug 3, 2020 · 11 comments
Closed

关于 jupyter lab 安装 toc 后无法在侧边栏显示的问题 #211

Rick-Zo opened this issue Aug 3, 2020 · 11 comments

Comments

@Rick-Zo
Copy link

Rick-Zo commented Aug 3, 2020

刚开始课程时看到老师推荐TOC,安装完成后,在PowerShell直接使用指令:
jupyter labextension install @jupyterlab/toc
提示失败,没有装node.js,当时没有理会,略过了。

昨天重新尝试安装,按提示在nodejs.org下载安装后,还是不行。

在网上搜索,按照Jupyter Lab目录插件安装的说明操作,依次输入
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter labextension install @jupyterlab/toc

发现还是报错:

Building jupyterlab assets (build:prod:minimize)
-Exception in thread Thread-10:
Traceback (most recent call last):
File "c:\users\65602\scoop\apps\python37\current\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "c:\users\65602\scoop\apps\python37\current\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "c:\users\65602\scoop\apps\python37\current\lib\subprocess.py", line 1238, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 281: illegal multibyte sequence

An error occured.
IndexError: list index out of range
See the log file for details: C:\Users\65602\AppData\Local\Temp\jupyterlab-debug-bnq1_nhy.log
(log文件内容附在二楼)

查看过《#13 jupyter 安装 TOC 插件失败》的同学提问,我的账户是英文名,并且我在jupyter lab里可以看到TOC已经安装,只是在侧边没有显示
微信截图_20200803110000

然后又查了不显示插件的原因,发现可以在jupyter lab的地址后加**/nbextensions**,进行选择,勾选了toc后,重启后还是看不到toc。
微信截图_20200803110627

这个插件不是必要的,不过比较担心以后安装其他的插件会不会遇到类似问题,能使用的功能就少很多,麻烦老师和同学帮忙看看,感谢~

系统与环境

系统是win10 X64
运行jupyter和VSC没有问题。
相关安装包版本如下:
微信截图_20200803111129

@Rick-Zo
Copy link
Author

Rick-Zo commented Aug 3, 2020

log 文件内容

Node v12.18.3

Yarn configuration loaded.
Building jupyterlab assets (build:prod:minimize)
> node c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\staging\yarn.js install --non-interactive
yarn install v1.21.1
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
Done in 0.54s.

> node c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\staging\yarn.js yarn-deduplicate -s fewer --fail
yarn run v1.21.1
$ c:\users\65602\scoop\apps\python37\current\share\jupyter\lab\staging\node_modules\.bin\yarn-deduplicate -s fewer --fail
Done in 0.51s.

> node c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\staging\yarn.js run build:prod:minimize
Traceback (most recent call last):

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\debuglog.py", line 47, in debug_logging
    yield

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\labextensions.py", line 105, in start
    command=command, app_options=app_options)

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\commands.py", line 460, in build
    command=command, clean_staging=clean_staging)

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\commands.py", line 657, in build
    ret = self._run(['node', YARN_PATH, 'run', command], cwd=staging)

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\commands.py", line 1752, in _run
    return proc.wait()

  File "c:\users\65602\scoop\apps\python37\current\lib\site-packages\jupyterlab\commands.py", line 107, in wait
    out, _ = proc.communicate(timeout=.1)

  File "c:\users\65602\scoop\apps\python37\current\lib\subprocess.py", line 939, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)

  File "c:\users\65602\scoop\apps\python37\current\lib\subprocess.py", line 1288, in _communicate
    stdout = stdout[0]

IndexError: list index out of range

Exiting application: jupyter

@neolee
Copy link
Owner

neolee commented Aug 3, 2020

这种问题通常是插件没装好导致的,删了重装应该就可以,你后面的一些尝试其实不是必需的(例如 jupyter_contrib_nbextensions 这种)。

首先确保你的 nodejs 装好了并且可用,我们的配置指南中建议用 sccop install nodejs 来安装,不过你直接官网下载安装理论上也没问题,可以用 node -v 命令来看看是不是装好了。

然后卸掉之前安装的 toc:jupyter labextension uninstall @jupyterlab/toc,确认这个过程无错误出现。

最后重新安装:jupyter labextension install @jupyterlab/toc

@neolee neolee changed the title 关于jupyter lab安装toc后无法在侧边栏显示的问题 关于 jupyter lab 安装 toc 后无法在侧边栏显示的问题 Aug 3, 2020
@Rick-Zo
Copy link
Author

Rick-Zo commented Aug 3, 2020

好的,谢谢老师,nodejs 是安装了 v12.18.3 版本,可以查到。然后使用命令卸载,会报错:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa4 in position 281: illegal multibyte sequence
IndexError: list index out of range

输入卸载的命令后,打开 jupyter lab 是可以看到在 install 一栏里没有了,再使用命令安装后刷新页面,可以在这里看到,只是左侧还是没有显示 toc 插件。

微信截图_20200803122439
微信截图_20200803122750

在进入 ./nbextensions 勾选 toc后,刷新页面也还是不显示。

是不是还有其他地方要设置显示这个插件?

@neolee
Copy link
Owner

neolee commented Aug 3, 2020

这个 UnicodeDecodeError 是核心问题,为啥你这里会用到 gbk 编码,这是很古老的中文编码,现在基本不会用了。

具体解决方案还要搜搜。

@xuzhengfu
Copy link

Does this work for you?

open your terminal, and run:

npm config set unicode false

reference

  1. Jupyter labextension install issue

@Rick-Zo
Copy link
Author

Rick-Zo commented Aug 3, 2020

这个 UnicodeDecodeError 是核心问题,为啥你这里会用到 gbk 编码,这是很古老的中文编码,现在基本不会用了。

具体解决方案还要搜搜。

这个python也是在课程开始时用 sccop 安装的,不太清楚为啥会用到这个 (:з」∠)

并且每次提示出现错误的 .py 文件还都是不同,也没法修改单个文件,我再搜下这要怎么解决

我发现在启动 jupyter lab 的时候也是会有Unicode相关的提示,不清楚是不是有关联的,我再查查
微信截图_20200803135958

@Rick-Zo
Copy link
Author

Rick-Zo commented Aug 3, 2020

@xuzhengfu
sorry, it doesn't work for me.
微信截图_20200803135958

@xuzhengfu
Copy link

xuzhengfu commented Aug 3, 2020

It seems to be the problem in jupyterlab/jupyterlab#5345.

Suppose you have Python installed as required by the course, run the following commands in Windows Terminal:

task 1

cd C:\Users\<username>\scoop\apps\python37\3.7.4\Lib
code .\site.py

then, change line 480, from with open(virtual_conf, encoding='xxxx') as f: to with open(virtual_conf, encoding='utf-8') as f:

task 2

cd C:\Users\xuzhengfu\scoop\apps\python37\3.7.4\Lib\site-packages\traitlets
code .\traitlets.py

then, change line 2050, from return value.decode('ascii', 'strict') to return value.decode('UTF-8', 'strict')

@neolee
Copy link
Owner

neolee commented Aug 4, 2020

我都不知道 Python 还有这么个 bug(看原 po 似乎是 2.7 版本的?), @DerickZo 同学赶紧试试,告诉我们是不是这个问题,结果如何……

我看了下,我的 site.py 文件没问题,本身就是 utf-8,然是 Jupyter 用到的 traitlets 包里的 traitlets.py 那一行确实是 ascii,但我没改过似乎也没遇到问题……

@Rick-Zo
Copy link
Author

Rick-Zo commented Aug 4, 2020

@xuzhengfu Thank you!But it doesn't work...

刚才按步骤尝试进行修改:

site.py line 480 原本就是 encoding='utf-8' ,不需要修改。
traitlets.py line 2050 原本是 'ascii' ,改成 'UTF-8'
0804-1
0804-2

保存文件后重启电脑,输入安装命令,发现还是同样的报错内容。
0804-3

读写文件相关的解决方法我查过一些,是在我们常规写函数时读写文件要使用某个字符集,就像刚才做的修改,但是在python3安装插件时遇到这类报错,还没找到具体的解决方法。
报错内容里提到的文件我打开看过,是用来执行读写的通用函数,也没有设置Unicode相关的参数,应该是读写的具体文件有问题,这个没法定位具体是哪里出了问题......

@royqh1979
Copy link

找到python安装目录的lib\site-packages\jupyterlab\commands.py文件,
第83行:

   self.proc = self._create_process(
        cwd=cwd,
        env=env,
        stderr=subprocess.STDOUT,
        stdout=subprocess.PIPE,
        universal_newlines=True
    )

修改为:

    self.proc = self._create_process(
        cwd=cwd,
        env=env,
        stderr=subprocess.STDOUT,
        stdout=subprocess.PIPE,
        universal_newlines=True,
        encoding="UTF-8"
    )

也就是增加一个参数encoding="UTF-8",就可以了

@neolee neolee closed this as completed Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants