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

Mac OS 12.2下pip莫名使用无效代理致安装失败的问题求助

解决Mac OS 12.2下pip代理解析错误问题

每次运行pip时,除非在命令行指定有效代理,否则都会报错:

ERROR: Could not install packages due to an OSError: Failed to parse: http://localhost:3128:443

尝试设置--proxy=""仍无效,只有指定有效--proxy=PROXYURL时pip才能正常工作。已确认环境无代理变量,也找不到任何pip配置文件:

~ $ env | grep -i proxy # 无返回,未设置代理环境变量
~ $ ls "/Library/Application Support/pip/pip.conf"
ls: /Library/Application Support/pip/pip.conf: No such file or directory
~ $ ls ".config/pip/pip.conf"
ls: .config/pip/pip.conf: No such file or directory
~ $ ls "Library/Application Support/pip/pip.conf"
ls: Library/Application Support/pip/pip.conf: No such file or directory
~ $ ls "$VIRTUAL_ENV/pip.conf"
ls: /pip.conf: No such file or directory
~ $ export PIP_CONFIG_FILE=os.devnull
~ $ pip3 install -U auto-sklearn
ERROR: Could not install packages due to an OSError: Failed to parse: http://localhost:3128:443

WARNING: There was an error checking the latest version of pip.

解决方案

  • 检查系统级网络代理设置
    打开「系统偏好设置」→「网络」,选中当前网络(Wi-Fi/以太网),点击「高级」→「代理」标签,确认所有代理选项都已取消勾选,尤其是自动代理配置(PAC)、HTTP/HTTPS代理这些。如果之前配置过PAC文件,清空对应的URL并取消勾选。

  • 手动创建pip配置文件禁用代理
    执行以下命令生成全局pip配置文件,明确清空代理设置:

    mkdir -p ~/.config/pip
    echo -e "[global]\nproxy=" > ~/.config/pip/pip.conf
    

    创建完成后重启终端,重新运行pip命令测试。

  • 排查虚拟环境隐藏配置
    若使用虚拟环境,进入环境目录检查是否存在隐藏的pip配置文件:

    ls -la $VIRTUAL_ENV | grep pip
    

    若发现pip.conf或pip.ini文件,直接删除或清空其中的代理相关内容。

  • 升级pip到最新版本
    在能连接代理的环境下执行升级命令:

    pip3 install --upgrade pip --proxy=PROXYURL
    

    升级完成后再尝试不带代理运行pip。

  • 刷新系统网络缓存
    执行以下命令刷新DNS缓存:

    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    

    重启终端后再次测试pip。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 12:57:36