Skip to content

安装 Poetry 到 D 盘

  1. 创建目标目录

    在 D 盘创建:

    • D:\software\poetry
  2. 使用官方安装脚本安装到 D 盘

    打开 PowerShell(推荐用 PowerShell,因为 curl 命令更友好):

    powershell
    # 先设置 Poetry 的 HOME 到 D 盘(很重要!)
    $env:POETRY_HOME = "D:\software\poetry"
    
    # 然后运行官方安装脚本
    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

    或者用 cmd:

    cmd
    set POETRY_HOME=D:\software\poetry
    curl -sSL https://install.python-poetry.org | python -

    安装完成后,Poetry 的可执行文件会出现在:

    • D:\software\poetry\bin\poetry.exe
  3. 添加 Poetry 到系统 PATH(让命令行直接识别 poetry)

    • 右键 此电脑 → 属性 → 高级系统设置 → 环境变量
    • 在“系统变量”或“用户变量”中找到 Path → 编辑 → 新增
    • 添加:D:\software\poetry\bin
    • 确定 → 关闭所有窗口

    然后重新打开一个命令提示符,输入:

    bash
    poetry --version

    看到版本号说明安装成功。

步骤 3:配置 Poetry 所有数据都放在 D 盘

安装完后,立刻设置以下路径,避免以后又把缓存写到 C 盘:

bash
poetry config cache-dir "D:\software\poetry\Cache"

poetry config virtualenvs.path "D:\software\poetry\virtualenvs"

# 推荐:让虚拟环境创建在项目目录内部(.venv 文件夹)
poetry config virtualenvs.in-project true

设置完成后,运行 poetry config --list 检查是否生效。

步骤 4:验证 & 后续使用

  1. 进入一个 Python 项目目录
  2. 运行 poetry install 测试是否正常创建虚拟环境(应该出现在项目目录下的 .venv,或 D:\software\poetry\virtualenvs)
  3. 用 WizTree 再扫一次 C 盘,确认 pypoetry 相关文件夹已消失或只剩很小残留。

注意事项

  • 如果你之前项目里有 poetry.lock 和 pyproject.toml,直接保留它们,运行 poetry install 就能恢复依赖。
  • 迁移完成后,C 盘应该能释放 10–13 GB 左右。
  • 以后新建项目时,Poetry 的缓存和虚拟环境都会自动写到 D 盘。

Released under the MIT License.