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

如何配置PyCharm以使用PDM下载的Python依赖包?

问题:PyCharm未使用PDM管理的依赖包

我正在使用PDM管理Python项目依赖,发现PyCharm并未使用PDM已下载的包,而是自行下载旧版本依赖:PDM已将包更新至0.1.34,但PyCharm仍使用旧版0.1.29,且会重复下载相同包。想知道是否可配置PyCharm使用PDM下载的包,或是有操作遗漏。

环境信息

PDM基础信息

> pdm info
PDM version:
  2.10.4
Python Interpreter:
  /Users/xiaoqiangjiang/source/dolphin/visa/.venv/bin/python (3.10)
Project Root:
  /Users/xiaoqiangjiang/source/dolphin/visa
Local Packages:

PDM环境详情

> pdm info --env
{
  "implementation_name": "cpython",
  "implementation_version": "3.10.11",
  "os_name": "posix",
  "platform_machine": "arm64",
  "platform_release": "22.4.0",
  "platform_system": "Darwin",
  "platform_version": "Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000",
  "python_full_version": "3.10.11",
  "platform_python_implementation": "CPython",
  "python_version": "3.10",
  "sys_platform": "darwin"
}

PyCharm版本信息

PyCharm 2023.2.5 (Community Edition)
Build #PC-232.10227.11, built on November 14, 2023
Runtime version: 17.0.9+7-b1000.46 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 10
Metal Rendering is ON
Registry:
    debugger.new.tool.window.layout=true
    ide.experimental.ui=true

解决方法

1. 绑定PDM创建的虚拟环境

  • 打开PyCharm,进入File > Project Structure > Project Settings > Project
  • 在Python Interpreter下拉菜单中,选择PDM创建的虚拟环境路径:/Users/xiaoqiangjiang/source/dolphin/visa/.venv/bin/python
  • 若列表中无该环境,点击右侧齿轮图标,选择Add > Virtualenv Environment > Existing environment,手动指定上述路径

2. 配置PyCharm用PDM管理依赖

  • 进入File > Settings > Tools > Python Integrated Tools
  • 在Package Management的Package installer下拉菜单中选择PDM
  • 取消勾选Use pip,让PyCharm直接调用PDM处理依赖

3. 同步依赖并刷新

  • 执行终端命令pdm sync更新依赖
  • 回到PyCharm,点击Python解释器旁的刷新按钮,同步依赖列表
  • 可右键点击External Libraries下的当前解释器,选择Show in Explorer,确认依赖包路径与PDM一致

4. 清除PyCharm缓存

  • 进入File > Invalidate Caches...,选择Invalidate and Restart,清除旧缓存避免加载旧版本包

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 18:32:31