7

When i run

    pip install --upgrade pip

I get this error message:

    Collecting pip
    Downloading pip-8.1.0-py2.py3-none-any.whl (1.2MB)
    100% |████████████████████████████████| 1.2MB 371kB/s 
    Installing collected packages: pip
    Found existing installation: pip 8.0.2
    Uninstalling pip-8.0.2:
    Exception:
    Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line       209, in main
    status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line  725, in install
    requirement.uninstall(auto_confirm=True)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 752, in uninstall
    paths_to_remove.remove(auto_confirm)
    File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py",line 115, in remove
    renames(path, new_path)
    File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 266,   in renames
    shutil.move(old, new)
    File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
    OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site- packages/pip-8.0.2.dist-info/DESCRIPTION.rst'

Previously I had been struggling to install and run a couple of python modules so I remember moving files around a bit. Is that what has caused this error? How can I fix this? I am on Mac.

I was trying to install bs4 prior to this and I got similar error messages. (But i suspect the bs4 install has more issues so that's another question for later).

Also sorry for any format issues with the code. Have tried my best to make it look like it is on the terminal.

Thanks.

C2P1
  • 397
  • 2
  • 4
  • 13
  • 1
    if you run `pip list --outdated` it will show which modules are out of date, but doing so will give you the correct way to update pip if it's out of data, you should be doing `python -m pip install pip --upgrade` – James Kent Mar 09 '16 at 14:40
  • `Permission denied` sounds like a permission issue, what OS are you on? – Tadhg McDonald-Jensen Mar 09 '16 at 14:40
  • I'm on Mac. Will add this into original post – C2P1 Mar 09 '16 at 14:44
  • 3
    sudo pip install -U pip? – YOBA Mar 09 '16 at 14:45
  • Thanks @YOBA, that worked! Problem solved. – C2P1 Mar 09 '16 at 14:46
  • I think what happens is, pip tries to delete itself while it is running (which results in an access denied error). Running `python -m pip install --upgrade pip` doesn't cause that issue, as then (atleast on Windows) `pipX.X.exe` (wrapper) is not the process executing it but `python.exe` is executing it – demberto Feb 12 '22 at 16:47

4 Answers4

6

A permission issue means your user privileges don't allow you to write on the desired folder(/Library/Python/2.7/site-packages/pip/). There's basically two things you can do:

  1. run pip as sudo:

    sudo pip install --upgrade pip
    
  2. Configure pip to install only for the current user, as covered here and here.
Community
  • 1
  • 1
Bernardo Meurer
  • 2,295
  • 5
  • 31
  • 52
3

The best way to do it is as follows:

$ python3 -m pip install --upgrade pip

as it's generally not advised to use

$ sudo pip install

More answers can be found here: https://github.com/pypa/pip/issues/5599

kgebreki
  • 51
  • 5
1

From administrator mode command prompt, you can run the following command, that should fix the issue:

python -m ensurepip --user

Replace python3 if your version supports that.

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
pgaur
  • 11
  • 1
0
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirement.txt'
WARNING: You are using pip version 19.2.3, however version 20.3.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip install pip
Requirement already satisfied: pip in /data/data/com.termux/files/usr/lib/python3.9/site-packages (21.0.1) 

Showing like this help !!!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Drax
  • 1