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

无法在Visual Studio Community 2022中安装Python包求助

问题描述

每次通过Python Environments安装Python包都会触发相同错误,已多次重装Python和Visual Studio Community 2022,问题仍未解决。安装requests时的错误日志如下:

----- Installing 'requests' -----
Collecting requests
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1780>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1A20>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1BA0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1C90>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1E10>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/ca/91/6d9b8ccacd0412c08820f72cebaa4f0c0441b5cda699c90f618b6f8a1b42/requests-2.28.1-py3-none-any.whl (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x00000238A9EF1F90>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))
[notice] A new release of pip available: 22.2.1 -> 22.2.2
[notice] To update, run: python.exe -m pip install --upgrade pip
----- Failed to install 'requests' -----

此外,尝试更新pip时出现语法错误,无法完成更新。

解决方案

一、解决连接超时问题

1. 使用国内PyPI镜像源

  • 单次安装指定镜像:
    pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  • 配置永久镜像源:
    1. 在Windows用户目录下创建pip文件夹(路径示例:C:\Users\你的用户名\pip)
    2. 新建pip.ini文件,写入以下内容:
      [global]
      index-url = https://pypi.tuna.tsinghua.edu.cn/simple
      [install]
      trusted-host = pypi.tuna.tsinghua.edu.cn
      

2. 调整pip超时时间

增加连接超时阈值,给pip更多时间建立连接:

pip install requests --default-timeout=60

3. 检查网络代理设置

  • 关闭当前运行的代理工具(VPN、代理软件等),尝试直接连接
  • 若系统有全局代理配置,临时关闭后再执行安装命令

二、解决pip更新语法错误问题

1. 确认命令正确性

确保更新pip的命令输入无拼写或符号错误:

python.exe -m pip install --upgrade pip

若为Python3环境,可替换为python3 -m pip install --upgrade pip(根据自身环境调整)

2. 手动下载pip包更新

如果命令行更新失败,手动下载wheel包安装:

  1. 下载对应版本的pip wheel包(如pip-22.2.2-py3-none-any.whl)
  2. 切换到下载目录,执行安装命令:
    pip install pip-22.2.2-py3-none-any.whl
    

3. 检查环境变量配置

确保Python的Scripts目录已添加到系统环境变量中,避免执行pip时出现路径错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 18:51:32