You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Mac下brew update遇Permission denied错误,求非sudo方案及Python3替代安装法

Fixing Brew Permission Error for Python3 Installation (Without Sudo)

Hey there, let's work through this issue together—no sudo required, promise!

First: Fix the Brew Permission Issue

The error you're hitting happens because your user account doesn't have the right permissions to create or access /usr/local/Frameworks. Here's how to fix it properly:

  1. Create the Frameworks directory and set correct ownership
    Run these commands in your terminal (the sudo here is only for a one-time ownership fix, not running brew itself):

    mkdir -p /usr/local/Frameworks
    sudo chown -R $(whoami):admin /usr/local/Frameworks
    
  2. Relink or reinstall Python3
    Now try linking the formula again:

    brew link python3
    

    If that still fails, reinstall Python3 with brew:

    brew reinstall python3
    
  3. Fix broader /usr/local permission issues (if needed)
    Sometimes other subdirectories in /usr/local might have incorrect ownership too. Fix those with:

    sudo chown -R $(whoami):admin /usr/local/bin /usr/local/lib /usr/local/sbin /usr/local/share /usr/local/etc
    

    This ensures your user owns all the directories brew needs to operate, preventing future permission headaches.

Alternative Ways to Install Python3 on Mac (No Brew Needed)

If you'd rather skip brew entirely, here are reliable, hassle-free options:

  • Official Python Installer
    Grab the installer for your desired Python version (3.6.5 in your case) directly from the Python official release page. It will automatically set up python3 and pip3 in your system path, and install Python to /Library/Frameworks/Python.framework/.

  • pyenv (For Version Management)
    pyenv is ideal if you need to switch between multiple Python versions. Install it via git:

    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    

    Then add these lines to your shell config file (.zshrc for Zsh, .bash_profile for Bash):

    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init --path)"
    

    Reload your shell with source ~/.zshrc (or the appropriate file), then install Python 3.6.5:

    pyenv install 3.6.5
    pyenv global 3.6.5 # Set this as your default system Python
    
  • Miniconda/Anaconda
    Perfect for data science workflows—comes preloaded with popular scientific libraries. Download the lightweight Miniconda installer, run it, then use conda to manage your Python environment:

    conda create -n py36 python=3.6.5
    conda activate py36
    

A quick note: Avoid running brew with sudo unless it's absolutely necessary. It causes files to be owned by root, which leads to ongoing permission issues like the one you're facing. Fixing directory ownership is the safe, recommended approach from the brew team.

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

火山引擎 最新活动