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

Windows11下WSL Ubuntu子系统pip安装flask-sqlalchemy失败求助

问题描述

在Windows 11的Ubuntu子系统(WSL)虚拟环境中执行命令:

pip install flask-sqlalchemy

出现以下网络相关错误:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff5c27dff10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/flask-sqlalchemy/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff5c2620280>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/flask-sqlalchemy/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff5c2620520>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/flask-sqlalchemy/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff5c26206d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/flask-sqlalchemy/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff5c2620880>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/flask-sqlalchemy/
ERROR: Could not find a version that satisfies the requirement flask-sqlalchemy (from versions: none)
ERROR: No matching distribution found for flask-sqlalchemy  

该操作在独立Linux系统中可正常执行,判断问题与WSL网络连接有关。

解决方法
  • 修复WSL DNS配置

    1. 编辑DNS配置文件:
      sudo nano /etc/resolv.conf
      
    2. 将原有的nameserver替换为公共DNS,比如:
      nameserver 8.8.8.8
      nameserver 114.114.114.114
      
    3. 保存退出后,执行以下命令锁定文件防止WSL自动重置:
      sudo chattr +i /etc/resolv.conf
      
  • 切换pip至国内镜像源

    • 临时使用国内源安装:
      pip install flask-sqlalchemy -i https://pypi.tuna.tsinghua.edu.cn/simple
      
    • 配置永久国内源:
      1. 创建pip配置目录及文件:
        mkdir -p ~/.pip && nano ~/.pip/pip.conf
        
      2. 写入以下内容并保存:
        [global]
        index-url = https://pypi.tuna.tsinghua.edu.cn/simple
        
  • 重启WSL服务
    在Windows的命令提示符(CMD)或PowerShell中执行:

    wsl --shutdown
    

    之后重新打开WSL终端,再尝试安装命令。

  • 检查WSL版本与网络模式

    1. 确保使用WSL 2版本(若当前是WSL 1,可执行升级命令):
      wsl --set-version Ubuntu 2
      
    2. 若仍有问题,尝试重置Windows网络组件后重启电脑:
      netsh winsock reset
      netsh int ip reset all
      netsh winhttp reset proxy
      ipconfig /flushdns
      

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 12:30:52