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

如何配置PyCharm使其自动安装缺失的Python包?

配置PyCharm自动安装缺失Python包的方法
  • 开启自动安装触发机制

    1. 打开PyCharm,进入File > Settings(Windows/Linux)或PyCharm > Settings(Mac)
    2. 展开Project: [你的项目名] > Python Interpreter,点击右上角齿轮图标选择Show All,选中当前使用的解释器后确认
    3. 在解释器页面勾选Install missing packages automatically;如果找不到该选项,就进入Editor > Inspections > Python > Unresolved reference,勾选该检查项后,将快速修复设置为自动安装缺失包
  • 用requirements.txt批量同步依赖

    1. 在项目根目录创建requirements.txt文件,把所有需要的依赖包列进去(示例:requests==2.31.0)
    2. 进入Python Interpreter设置页面,点击左上角的+号,再选择Install from requirements,选中你的requirements.txt文件,PyCharm会自动安装所有缺失的包
    3. 还可开启自动同步:进入Settings > Tools > Sync Requirements,勾选Automatically sync requirements.txt with project packages,之后修改依赖列表会自动同步安装
  • 运行时快速修复缺失包
    当代码里的包名出现红色下划线时,将光标移至包名上,按下Alt + Enter(Windows/Linux)或Option + Enter(Mac),在弹出菜单中选择Install package [包名],PyCharm就会自动下载安装该包。若想让操作更省心,可进入Settings > Editor > General > Auto Import调整Python自动导入设置,开启自动安装相关选项

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 02:18:20