code-server 移动ipynb文件后无法运行的问题

code-server 移动ipynb文件后无法运行的问题

问题描述:

1、docker方式安装了code-server在线编辑器
2、移动了ipynb文件后,发现无法运行单元格内的代码,运行出错。错误信息包含如下:
/usr/bin/python3 -m pip install ipykernel -U --user --force-reinstall
疑似jupyter内核的问题,需要重新安装内核。然而如果按以上命令重新安装的话,又会跳出如下错误:
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.

If you wish to install a non-brew-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.

If you wish to install a non-brew packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing –break-system-packages.
hint: See PEP 668 for the detailed specification.

解决方法:

1、经过查找,发现问题其实很简单。因为code-servervs code一样是基于工作区的,在起初安装code-server后建立的虚拟环境是与工作区绑定的,当我把原位置的ipynb文件移动到其它位置时,这种绑定被破坏了。需要在在新的工作区重新建立虚拟环境,并启用内核。

2、还有一个办法,就是把原来的.venv文件夹复制到新的工作区,并编辑其根下的pyvenv.cfg文件,更改command 参数。这个办法我没有试,应该也是可以的。

PS:这个问题没有截图。遇到这个问题的同学应该知道我说的是什么。