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

M1 Mac Ventura下Homebrew安装Python@3后post-install步骤失败求助

Homebrew安装Python@3.11后Post-install失败的解决办法

环境信息

  • M1 Mac,系统版本Ventura 13.0
  • Homebrew版本4.0.6

问题描述

执行brew install python@3安装Python后,post-install步骤失败;重试brew postinstall python@3.11问题依旧。

关键错误日志

==> //opt/homebrew/Cellar/python@3.11/3.11.2_1/bin/python3.11 -m ensurepip
==> //opt/homebrew/Cellar/python@3.11/3.11.2_1/bin/python3.11 -m pip install -v --no-deps --no-index --upgrade --isolated --target=//opt/homebrew/lib/python3.11/site-
最后15行日志来自 /Users/zhangfan/Library/Logs/Homebrew/python@3.11/post_install.02.python3.11:
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_internal/cli/req_command.py", line 411, in get_requirements
    req_to_add = install_req_from_line(
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_internal/req/constructors.py", line 395, in install_req_from_line
    return InstallRequirement(
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_internal/req/req_install.py", line 127, in __init__
    self.local_file_path = self.link.file_path
                           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_internal/models/link.py", line 330, in file_path
    return url_to_path(self.url)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_internal/utils/urls.py", line 43, in url_to_path
    raise ValueError(
ValueError: 该平台不支持非本地文件URI: 'file://opt/homebrew/Cellar/python%403.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ensurepip/_bundled/setuptools-65.6.3-py3-none-any.whl'
警告: Post-install步骤未成功完成
你可以尝试再次执行:
  brew postinstall python@3.11

错误原因

错误核心是pip无法处理非本地文件URI,问题出在文件路径格式:file://opt/...缺少根路径的斜杠,正确格式应为file:///opt/...(三个斜杠)。这是Homebrew生成pip安装命令时的路径格式错误导致的。

解决步骤

  • 卸载当前Python@3.11
    brew uninstall python@3.11
    
  • 清理残留文件
    rm -rf /opt/homebrew/Cellar/python@3.11
    rm -rf /Users/zhangfan/Library/Logs/Homebrew/python@3.11
    
  • 重新安装Python@3.11
    brew install python@3.11
    
  • 手动补全post-install(若仍失败)
    直接调用ensurepip完成pip和setuptools的安装:
    /opt/homebrew/Cellar/python@3.11/3.11.2_1/bin/python3.11 -m ensurepip --upgrade --default-pip
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 08:12:52