2 min read

Installing Python Packages with Pip Without Sudo on macOS Tahoe

When installing Python packages with pip, you might encounter permission errors that prompt you to use sudo. However, it's generally not recommended to use sudo pip because it can lead to issues with file ownership and conflicts with system-level Python packages. A better approach is to install packages in your user space, either globally for your user or within a virtual environment.

1. User-Level Installation (Global)

You can configure pip to install packages in your home directory by default. This avoids the need for sudo and keeps your system clean.

Configure Pip

  1. Create a pip directory in your home directory if it doesn't exist:

    mkdir -p ~/.pip
  2. Create a pip.conf file in the .pip directory:

    nano ~/.pip/pip.conf
  3. Add the following lines to pip.conf:

    [install]
    prefix = ~/.local
    
    [ Lis ]
    
    [uninstall]
    prefix = ~/.local

    This tells pip to install packages under the ~/.local directory.

  4. Update Your PATH: Add ~/.local/bin to your PATH so that the executables installed by pip are accessible. Edit your ~/.zshrc (or ~/.bashrc) file:

    export PATH="$HOME/.local/bin:$PATH"
  5. Apply changes:

    source ~/.zshrc

Using a virtual environment is the best way to manage dependencies for each of your projects. See the guide for venv for more details.

  • Installing Python in User Space with Miniconda on macOS Tahoe
  • Configuring the Zsh Profile and PATH on macOS Tahoe
  • Creating Python Virtual Environments with venv on macOS Tahoe