9

I have done a fresh Windows 10 install, installed python, cygwin and a improved console called ConEmu. After installing python 3.4.3 I execute:

pip install -U pip

And got this error.

File "C:\Anwendungsentwicklung\Python34\lib\site-packages\pip\utils\__init__.py", line 70, in rmtree_errorhandler
  os.makedirs(path)
PermissionError: [WinError 5] Zugriff verweigert:  'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-dxm8d3xg-uninstall\\anwendungsentwicklung\\python34\\scripts\\pip.exe'

I'm logged in with pre-defined Administrator account and the temp dir as well as the installation dir of Python (C:\Anwendungsentwicklung\Python34) has full access.

Please I have tested all variations by setting different rights but Windows won't let me. I even added "Everyone" to security tab but this didn't help although I remember it was working with Windows 7 with this "trick". It must be a problem with Windows 10. Can someone help??

enter image description here


This is full traceback

  Exception:
Traceback (most recent call last):
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 372, in  _rmtree_unsafe
  os.unlink(fullname)
PermissionError: [WinError 5] Zugriff verweigert:  'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-k7g0hd6t- uninstall\\anwendungsentwicklung\\python34\\scripts\\pip.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\basecommand.py", line 232, in main
  logger.critical('Operation cancelled by user')
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\commands\install.py", line 347, in run
  ensure_dir(options.target_dir)
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\req\req_set.py", line 560, in install
  missing_requested = sorted(
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\req\req_install.py", line 677, in commit_uninstall
  logger.debug(
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\req\req_uninstall.py", line 153, in commit
  self.save_dir = None
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\utils\__init__.py", line 58, in rmtree
  SUPPORTED_EXTENSIONS = ZIP_EXTENSIONS + TAR_EXTENSIONS
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 484, in rmtree
  return _rmtree_unsafe(path, onerror)
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 368, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 368, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 368, in _rmtree_unsafe
  _rmtree_unsafe(fullname, onerror)
File "c:\anwendungsentwicklung\python34\lib\shutil.py", line 376, in _rmtree_unsafe
  print(fullname)
File "c:\anwendungsentwicklung\python34\lib\site-packages\pip\utils\__init__.py", line 70, in rmtree_errorhandler
  try:
PermissionError: [WinError 5] Zugriff verweigert: 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-k7g0hd6t-uninstall\\anwendungsentwicklung\\python34\\scripts\\pip.exe'

Now I added a breakpoint in "c:\anwendungsentwicklung\python34\lib\shutil.py":

# version vulnerable to race conditions
def _rmtree_unsafe(path, onerror):
try:
    if os.path.islink(path):
        # symlinks to directories are forbidden, see bug #1669
        raise OSError("Cannot call rmtree on a symbolic link")
except OSError:
    onerror(os.path.islink, path, sys.exc_info())
    # can't continue even if onerror hook returns
    return
names = []
try:
    names = os.listdir(path)
except OSError:
    onerror(os.listdir, path, sys.exc_info())
for name in names:
    fullname = os.path.join(path, name)
    try:
        mode = os.lstat(fullname).st_mode
    except OSError:
        mode = 0
    if stat.S_ISDIR(mode):
        _rmtree_unsafe(fullname, onerror)
    else:
        try:
            #import pdb
            os.unlink(fullname)
            #pdb.set_trace()
        except OSError:
            import pdb; pdb.set_trace()
            print(fullname)
            import getpass
            print(getpass.getuser())
            onerror(os.unlink, fullname, sys.exc_info())
try:
    os.rmdir(path)
except OSError:
    onerror(os.rmdir, path, sys.exc_info())

When i execute

os.unlink(fullname) # 'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-k7g0hd6t- uninstall\\anwendungsentwicklung\\python34\\scripts\\pip.exe'

I get this PermissionError, so i checked the rights of this .exe file with

oct(os.stat(fullname)[ST_MODE])

and it returns: '0o100777'

And when i'm right, this means full permission for everyone (owner, group and others).

I'm frustrated :/ Someone an idea?

7
  • Did you try running the command while being elevated?
    – poke
    Aug 20, 2015 at 19:43
  • It's not your ConEmu console -- I just upgraded and got the same error using the standard Cygwin console. Aug 20, 2015 at 19:45
  • @poke sure. But like Thane Plummer says, it doesn't matter which console. Windows 10 has something generally crapped -.-
    – FalloutBoy
    Aug 20, 2015 at 19:50
  • I meant running e.g. cmd.exe as administrator (via right-click).
    – poke
    Aug 20, 2015 at 20:01
  • 1
    @poke, the "Administrator" account (SID S-1-5-21-...-500) is disabled by default because it's not subject to UAC. It gets logged on with an unrestricted token that has the BUILTIN\Administrators (S-1-5-32-544) group enabled, an elevated (High) integrity label (S-1-16-12288), and the full set of administrator privileges such as SeTakeOwnershipPrivilege.
    – Eryk Sun
    Aug 20, 2015 at 23:26

5 Answers 5

13

As discussed here, it's a Windows limitation. In brief, the pip.exe file is in use and thus locked and can't be deleted. Use python -m pip install --upgrade pip.

3
  • Please give extra information by editing your question rather than adding it as an answer (which it isn't). Aug 20, 2015 at 23:47
  • @Roland Smith seen that in other threads, sorry. Solved the problem for me. It's a windows limitation and wasn't fixed since yet. Use python -m pip install --upgrade pip. Discussed here: github.com/pypa/pip/issues/1299 Summary: The file is locked/ in use and those files can't be deleted. Thanks all!
    – FalloutBoy
    Aug 20, 2015 at 23:53
  • @RolandSmith The question was "Can someone help?" and this post is an answer to that question. May 16, 2022 at 20:31
6

My first choice in the same situation is to start console with administrator rights. You can do that from start menu or if you are using ConEmu / Cmder, just run new instance / tab as administrator.

2
  • Just to clarify: open start menu, right click 'command prompt', select 'more', click 'Run as administrator'. Aug 27, 2016 at 17:15
  • Thanks. This helped !
    – Pirate X
    Dec 2, 2017 at 17:10
1

I had the same problem. It worked if you run cmd "as administrator" by right-clicking.

1

Try using this

python -m pip install --user --upgrade pip
0

We all know and have been frustrated with this error. With the fact that this problem is almost unsolvable, there is an option and this worked for me on Windows 11 Home. Virtualenv pip upgrades might not work correctly, even using python -m pip install --upgrade pip. This does not work for me, so I tried the following method on my system, to check out if upgrading pip was working on my local pip (not virtual environment):

PS C:\Windows\System32 >python -m pip install --upgrade pip

Requirement already satisfied: pip in (...)
Collecting pip
... Using cached pip-22.0.2-py3-none-any.whl (2.1 MB)
.. Installing collected packages: pip

(...)

Attempting uninstall: pip
Founded existing installation: pip 21.3.1
Uninstall pip-21.3.1:
... Successfully uninstalled (...)
ERROR: Could not install packages due to an OSError: [WinError 5] Access is Denied: 'C:\\Users\\USER\\AppData\\Local\\Temp\\pip-uninstall-8ob_krif\'
Consider using the '--user' option or check the permissions.
(...)
[WinError 5] Access Denied
(...)

PS C:\Windows\System32 >python -m pip install --upgrade pip


(...) [Summary: it says pip is on the latest version]

To summarize, when I ran the command again to check if pip was ACTUALLY upgraded, and the error message was fake, I was correct. pip WAS upgraded. It just said an error but seems like it actually upgraded it. Maybe because python just doesn't know the fact that it is actually upgraded. Some issue.

1
  • To summarize, pip is actually upgraded but that fact is not known by python or pip itself. And the error is just fake, or there was an error in the code, that tried to access another directory without elevation.
    – Andrew
    Jan 31, 2022 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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