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

创建Poetry新环境失败:ImportError无法从poetry.console导入main

解决Poetry导入'main'失败的问题

报错信息

Traceback (most recent call last):
  File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\lhott\AppData\Roaming\Python\Scripts\poetry.exe\__main__.py", line 4, in <module>
ImportError: cannot import name 'main' from 'poetry.console' (C:\Users\lhott\AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\__init__.py)

问题原因

手动删除原有Poetry环境后,残留的安装文件或配置与新环境冲突,导致Poetry核心模块加载失败。

解决方案

  • 彻底清理残留的Poetry文件
    1. 删除Poetry虚拟环境目录:C:\Users\lhott\AppData\Roaming\pypoetry
    2. 删除Scripts目录下的Poetry执行文件:C:\Users\lhott\AppData\Roaming\Python\Scripts\poetry.exe
    3. 打开系统环境变量设置,移除所有与Poetry相关的路径条目
  • 重新安装Poetry
    打开PowerShell,执行官方安装脚本:
    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
    
    安装完成后重启终端,验证poetry --version是否能正常输出版本信息
  • 重建项目环境
    进入你的Poetry项目目录,执行以下命令:
    poetry install
    
    若需要指定Python版本,执行:
    poetry env use python3.10
    

内容的提问来源于stack exchange,提问作者FluidMechanics Potential Flows

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 23:41:11