"Access is denied" while upgrading pip.exe on Windows

8.1k Views Asked by At

pip asked me to upgrade with a message:

You are using pip version 7.0.1, however version 7.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

So I ran that command and I get an exception that pip cannot uninstall the old version because access to my user directory is denied:

    Collecting pip
    Downloading pip-7.0.3-py2.py3-none-any.whl (1.1MB)
      100% |################################| 1.1MB 292kB/s
    Installing collected packages: pip
    Found existing installation: pip 7.0.1
    Uninstalling pip-7.0.1:
      Successfully uninstalled pip-7.0.1
    Exception:
    Traceback (most recent call last):
    File "C:\Python27\lib\site-packages\pip\basecommand.py", line 223, in main
    status = self.run(options, args)
    File "C:\Python27\lib\site-packages\pip\commands\install.py", line 297, in run

    root=options.root_path,
    File "C:\Python27\lib\site-packages\pip\req\req_set.py", line 633, in install
    requirement.commit_uninstall()
    File "C:\Python27\lib\site-packages\pip\req\req_install.py", line 734, in commit_uninstall
    self.uninstalled.commit()
    File "C:\Python27\lib\site-packages\pip\req\req_uninstall.py", line 153, in commit
    rmtree(self.save_dir)
    File "C:\Python27\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
    File "C:\Python27\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
    raise attempt.get()
    File "C:\Python27\lib\site-packages\pip\_vendor\retrying.py", line 247, in get

    six.reraise(self.value[0], self.value[1], self.value[2])
    File "C:\Python27\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
    File "C:\Python27\lib\site-packages\pip\utils\__init__.py", line 89, in rmtree
    onerror=rmtree_errorhandler)
    File "C:\Python27\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
    File "C:\Python27\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
    File "C:\Python27\lib\shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
    File "C:\Python27\lib\site-packages\pip\utils\__init__.py", line 101, in rmtree_errorhandler
    func(path)
    WindowsError: [Error 5] Access is denied: 'c:\\users\\chris\\appdata\\local\\temp\\pip-ossyhh-uninstall\\python27\\scripts\\pip.exe'

I'm running Windows 8.1, but I've had this same Error on another machine running Windows 7. It doesn't seem to stop the installation of the new version, but I do end up with pip folders left in my temp directory. Does anyone know why this happens or how I can correct it?

Edit1: Oddly, running the upgrade with admin privlidges throws a new exception:

File "C:\Python27\lib\site-packages\pip-7.0.1-py2.7.egg\pip\_vendor\distlib\scripts.py", line 302, in _get_launcher
result = finder(distlib_package).find(name).bytes
AttributeError: 'NoneType' object has no attribute 'bytes'`

And fails the upgrade entirely.

Edit2: The only way to get around this issue does seem to be using easy_install to upgrade pip (either the -U or -m options), but it seems like a problem to me if pip can't upgrade itself, when its intended (and stated) functionality is to do so.

4

There are 4 best solutions below

0
On BEST ANSWER

The problem here is apparently because you are running pip.exe to upgrade itself. So the pip.exe to be deleted is actually running at the time. The fix is to use a slightly different command line:

python -m pip install --upgrade pip

This is from this bug report (though there are others):

• Access is denied: '... pip.exe' is because you're upgrading pip using the pip.exe wrapper which gets replaced in the upgrade. On Windows you can't replace in-use executables/DLLs. You should use python -m pip install --upgrade pip . IIRC this is noted in the documentation.

0
On

I got the same problem recently on a windows 7 machine. I ran command prompt as administrator (from your comments), and then typed in pip install --upgrade pip.

It returned error messages out the wazoo, but then when I tried to do it again (pip install --upgrade pip), it told me pip was already up to date. Then pip -V told me I had pip 7.0.3.

No idea what is happening. Trying to get python packages on windows seems very difficult. Hope that was helpful.

Also, I'm using python 3.5, which may be different.

0
On

I faced the same problem . I simply used the SUDO command on my mac terminal and it worked. Below is the terminal output.

sudo pip install -U pip

Anuvrats-MacBook-Air:~ anuvrattiku$ pip -V
pip 7.1.2 from /Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg (python 2.7)
Anuvrats-MacBook-Air:~ anuvrattiku$ **sudo pip install -U pip**
Password:
The directory '/Users/anuvrattiku/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/anuvrattiku/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-8.0.2-py2.py3-none-any.whl (1.2MB)
100% |████████████████████████████████| 1.2MB 272kB/s 
Installing collected packages: pip
Found existing installation: pip 7.1.2
Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
Successfully installed pip-8.0.2
Anuvrats-MacBook-Air:~ anuvrattiku$ 
0
On

I also faced the issue while installing matplotlib using the pip-7.1.2 version so I upgraded it to pip 9.0.1.

However while updating it gave me an error of access denied to pip.exe but when I checked the version using pip -v it was updated. And I simply run pip install matplotlib. It worked for me.

D:\Users\703186511>pip install --upgrade pip

or try

D:\Users\703186511>python -m pip install --upgrade pip
D:\Users\703186511>pip -V
D:\Users\703186511>pip install matplotlib