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

在Codespaces中配置Python Poetry环境:选中解释器后导入仍未定义

解决VSCode远程连接Codespaces时Poetry解释器导入未定义问题
  • 确认Poetry环境在Codespaces中正常初始化

    1. 在Codespaces终端执行poetry install,确保所有项目依赖安装完成
    2. 运行poetry env info --path获取Poetry虚拟环境的绝对路径,示例路径:/home/codespace/.cache/pypoetry/virtualenvs/your-project-py3.10
    3. 对比VSCode中选中的解释器路径,若不一致,说明VSCode识别了错误的虚拟环境
  • 手动指定Python解释器路径

    1. 打开命令面板(Ctrl+Shift+P / Cmd+Shift+P),选择Python: Select Interpreter
    2. 点击Enter interpreter path...,粘贴上述获取的虚拟环境路径,再追加/bin/python,完整路径示例:/home/codespace/.cache/pypoetry/virtualenvs/your-project-py3.10/bin/python
  • 配置工作区设置锁定环境
    在项目根目录的.vscode/settings.json中添加以下配置,替换为你的实际环境路径:

    {
        "python.pythonPath": "/home/codespace/.cache/pypoetry/virtualenvs/your-project-py3.10/bin/python",
        "python.venvPath": "/home/codespace/.cache/pypoetry/virtualenvs/"
    }
    
  • 重启VSCode语言服务
    打开命令面板,选择Python: Restart Language Server,等待服务重启后检查导入提示是否消失

  • 核对终端环境路径一致性
    在Codespaces终端执行poetry shell激活环境,再运行which python,确认输出路径与VSCode选中的解释器路径一致,若不一致则重新指定解释器

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 10:42:24