Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 530
chris Avatar asked Jun 08 '15 00:06

chris


People also ask

How do I update pip to latest version of Windows?

Updating Pip b is available.” You can run “pip install --upgrade pip” to install and use the new version of pip. To update pip2 or pip3 using this command, only replace the first pip with the pip version.

Why pip is not working in cmd?

The error “'pip' is not recognized as an internal or external command” is encountered because of two main reasons that are. PIP Installation path is not added to the system variables: If you have installed python through prompt then you need to configure PIP path manually.


2 Answers

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.

like image 116
strubbly Avatar answered Sep 20 '22 06:09

strubbly


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.

like image 34
r12 Avatar answered Sep 18 '22 06:09

r12