Skip to content

Instantly share code, notes, and snippets.

@haircut
Created August 29, 2017 21:50
Show Gist options
  • Save haircut/14705555d58432a5f01f9188006a04ed to your computer and use it in GitHub Desktop.
Save haircut/14705555d58432a5f01f9188006a04ed to your computer and use it in GitHub Desktop.
How to install and use pip without sudo or admin on macOS

Install and use pip on macOS without sudo / admin access

Most recently tested on macOS Sierra (10.12.6)

  1. Download the installation script; curl https://bootstrap.pypa.io/get-pip.py -o ~/Downloads/get-pip.py
  2. Run the installation, appending the --user flag; python ~/Downloads/get-pip.py --user. pip will be installed to ~/Library/Python/2.7/bin/pip
  3. Make sure ~/Library/Python/2.7/bin is in your $PATH. For bash users, edit the PATH= line in ~/.bashrc to append the local Python path; ie. PATH=$PATH:~/Library/Python/2.7/bin. Apply the changes, source ~/.bashrc.
  4. Use pip! Remember to append --user when installing modules; ie. pip install <package_name> --user

Note

There is much discussion about making the user site the default for installation. See Issue 1668.

@dotku
Copy link

dotku commented Apr 2, 2019

I don't like "--user" postfix either :(

@bmatichuk
Copy link

after removing pip from /usr/local/bin and from anaconda3 I tried the above operation 1 & 2

  1. Download the installation script; curl https://bootstrap.pypa.io/get-pip.py -o ~/Downloads/get-pip.py
  2. Run the installation, appending the --user flag; python ~/Downloads/get-pip.py --user. pip will be installed to ~/Library/Python/2.7/bin/pip

however, this did not entirely solve the problem.
Running pip caused the following error
-bash: /Users//anaconda3/bin/pip: No such file or directory

To get this to work I had to do

sudo easy_install pip

Now it works.

The thing is - prior to doing steps 1 & 2 easy_install was causing a problem with pip
ImportError: cannot import name 'version' from 'pip' (unknown location)

??

@MacStevins
Copy link

As bmatichuk said, it did work with:

sudo easy_install pip

In MacOS High Sierra

@dashvlas
Copy link

dashvlas commented Jan 9, 2020

As bmatichuk said, it did work with:

sudo easy_install pip

In MacOS High Sierra

Still works on Catalina, thanx!😊

@rogfrich
Copy link

I'm trying to figure out where pip installs packages on MacOS Mojave. If I pip install cookiecutter - not in a venv - where do the files go? I ask because wherever it is does not seem to be in my $PATH - I can't type cookiecutter <source> <target> which is supposed to work. I get a command not found error. I installed Cookiecutter for my base Python install (at least I think I did) rather than in a venv because I want to be able to use it to create new projects from scratch.

@braysonjohn148
Copy link

works on Moave too

@rmendezbcn
Copy link

"sudo easy_install pip" worked on Catalina as well.
Thanks

@hannahbaker2
Copy link

More of a PSA, i'm learning automate the boring stuff with python and in the latest release, he suggests against sudo easy_install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment