16

I'm trying to upgrade pip on my iMac, but I keep getting a permission denied error. I'm the admin, so I don't know what I've done wrong.

iMac:~ me$ pip install --upgrade pip
    You are using pip version 6.0.8, however version 7.1.2 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    Collecting pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
      Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
        100% |################################| 1.1MB 181kB/s 
    Installing collected packages: pip
      Found existing installation: pip 6.0.8
        Uninstalling pip-6.0.8:
          Exception:
          Traceback (most recent call last):
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
              status = self.run(options, args)
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 347, in run
              root=options.root_path,
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 543, in install
              requirement.uninstall(auto_confirm=True)
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 667, in uninstall
              paths_to_remove.remove(auto_confirm)
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
              renames(path, new_path)
            File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/utils/__init__.py", line 316, in renames
              shutil.move(old, new)
            File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 300, in move
              rmtree(src)
            File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 247, in rmtree
              rmtree(fullname, ignore_errors, onerror)
            File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree
              onerror(os.remove, fullname, sys.exc_info())
            File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree
              os.remove(fullname)
          OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/EGG-INFO/dependency_links.txt'

I don't know what I've done wrong here as an upgrade seem fairly straightforward.

Thanks,

1
  • 2
    How about running it with 'sudo' in front?!
    – Cleb
    Commented Oct 4, 2015 at 17:24

3 Answers 3

24

pip installations require elevation

sudo pip install --upgrade pip

Just because you are currently using an admin account doesn't mean the command will run with elevation, unless you specify sudo

3
  • 2
    FWIW you should mention that it not good practice to use sudo with pip but virtual environment
    – Sede
    Commented Oct 4, 2015 at 17:29
  • 6
    WARNING: Running pip install with root privileges is generally not a good idea. Try 'pip install --user' instead.
    – jozxyqk
    Commented Aug 8, 2018 at 3:55
  • 1
    I use python3 -m pip install pip --user --upgrade in this situation.
    – Adam
    Commented Mar 31, 2022 at 20:45
3

You have to use sudo since you are upgrading pip "globally". I prefer to install Homebrew and let Homebrew manage everything.

  1. Install Xcode from the App Store
  2. Install Homebrew - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. Install Python - brew install python, which also installs pip.

With this setup, everything is installed locally, which doesn't require you to run sudo.

I hope this helps.

1
  • You can also install Python 3 with brew install python3. Commented Jul 29, 2016 at 16:02
2

You can do one of two ways:

  1. chown -R user /path/to/file a more detailed information can be found in this SO post, while it doesn't relate to the exact problem it deals with the same issue
  2. Quick and dirty way just do pip install --upgrade pip as already mentioned. However, many users will suggest against that.

Not the answer you're looking for? Browse other questions tagged or ask your own question.