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

求助:VS Code中安装Python模块时持续报错的解决方法

解决VS Code中Python模块安装失败的问题

从你提供的报错信息来看,核心问题是SSL证书验证失败和网络连接超时,以下是针对性的解决步骤:

1. 临时跳过SSL验证安装模块

如果是临时安装需求,执行命令时添加信任主机参数,示例(以安装requests为例):

pip install requests --trusted-host pypi.org --trusted-host files.pythonhosted.org

2. 配置国内PyPI镜像源

国内网络访问官方PyPI稳定性差,换成国内镜像能解决多数网络类问题:

  • 临时使用镜像:安装时指定国内源,比如阿里云镜像:
pip install requests -i https://mirrors.aliyun.com/pypi/simple/
  • 永久配置镜像:
    1. Windows用户在C:\Users\你的用户名目录下创建pip文件夹,再新建pip.ini文件;Linux/macOS用户在~目录下创建.pip文件夹,新建pip.conf文件
    2. 在文件中写入以下内容:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com

3. 确认VS Code的Python解释器

确保VS Code使用的是你更新后的Python版本:

  • 按Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(macOS),输入Python: Select Interpreter
  • 选择你安装的最新Python版本(若使用虚拟环境,选虚拟环境内的Python执行文件)

4. 确保虚拟环境已激活

使用虚拟环境时,必须先激活再执行安装命令:

  • Windows系统激活命令:
.\venv\Scripts\activate
  • Linux/macOS系统激活命令:
source venv/bin/activate

激活成功后终端开头会显示(venv)标识,再执行pip安装操作。

5. 配置网络代理(若需)

如果你的网络需要代理,给pip配置代理信息:

  • 临时设置代理(示例代理地址为http://127.0.0.1:1080):
pip install requests --proxy http://127.0.0.1:1080
  • 永久配置代理:在之前创建的pip.ini/pip.conf文件中添加一行:
proxy = http://127.0.0.1:1080

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 09:22:06