You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JupyterLab 4.1.5搭配pylsp出现virtual_documents权限错误求助

解决JupyterLab LSP虚拟文件系统权限错误问题

问题场景

使用JupyterLab 4.1.5,按官方指引通过pip安装pylsp后,LSP扩展显示初始化成功,但打开.ipynb文件时触发以下权限错误:

[W 2024-03-21 16:54:39.012 ServerApp] [lsp] initialization of shadow filesystem failed three times
check if the path set by LanguageServerManager.virtual_documents_dir or JP_LSP_VIRTUAL_DIR is correct;
if this is happening with a server for which you control (or wish to override) jupyter-lsp specification
you can try switching requires_documents_on_disk off. The errors were:
[PermissionError(13, 'Permission denied'), PermissionError(13, 'Permission denied'),
PermissionError(13, 'Permission denied')]

尝试关闭requires_documents_on_disk但未解决,不清楚正确配置方式。

解决方案

1. 检查并修复虚拟文档目录权限

  • JupyterLab默认会在以下路径创建虚拟文档目录:
    • Linux/macOS:~/.local/share/jupyter/lsp_virtual_documents
    • Windows:%APPDATA%\jupyter\lsp_virtual_documents
  • 检查目录权限:
    Linux/macOS执行:
    ls -ld ~/.local/share/jupyter/lsp_virtual_documents
    
    确保当前用户拥有读写权限,若权限不足,执行:
    chmod -R 700 ~/.local/share/jupyter/lsp_virtual_documents
    

2. 手动指定可写的虚拟文档目录

  • 生成Jupyter配置文件(若未生成):
    jupyter server --generate-config
    
  • 打开生成的jupyter_server_config.py,添加以下配置:
    c.LanguageServerManager.virtual_documents_dir = "/path/to/your/custom/writable/dir"
    
    替换为你有读写权限的目录,比如~/jupyter_lsp_virtual。

3. 正确配置requires_documents_on_disk(针对pylsp)

之前的设置可能未针对pylsp生效,需在配置中指定:

  • 打开jupyter_server_config.py,添加:
    c.LanguageServerManager.language_servers = {
        "pylsp": {
            "server_settings": {
                "pylsp": {
                    "general": {
                        "requires_documents_on_disk": False
                    }
                }
            }
        }
    }
    
  • 或使用环境变量临时生效:
    Linux/macOS:
    export JP_LSP_PYLSP_GENERAL_REQUIRES_DOCUMENTS_ON_DISK=false
    jupyter lab
    
    Windows(PowerShell):
    $env:JP_LSP_PYLSP_GENERAL_REQUIRES_DOCUMENTS_ON_DISK="false"
    jupyter lab
    

4. 验证修复

重启JupyterLab,打开.ipynb文件,查看日志是否仍有权限错误提示。

内容的提问来源于stack exchange,提问作者Hutch3232

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 16:30:16