Pip: On windows, pip install -U pip fails if TEMP is on different drive letter.

Created on 11 Jul 2015  路  8Comments  路  Source: pypa/pip

> pip install -U pip
You are using pip version 7.0.3, however version 7.1.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Collecting pip
  Downloading pip-7.1.0-py2.py3-none-any.whl (1.1MB)
    100% |################################| 1.1MB 120kB/s
Installing collected packages: pip
  Found existing installation: pip 7.0.3
    Uninstalling pip-7.0.3:
Exception:
Traceback (most recent call last):
  File "C:\Develop\Python34\lib\shutil.py", line 522, in move
    os.rename(src, real_dst)
OSError: [WinError 17] The system cannot move the file to a different disk drive: 'c:\\develop\\python34\\scripts\\pip.exe' -> 'D:\\TEMP\\pip-ugv4c2uf-uninstall\\develop\\python34\\scripts\\pip.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Develop\Python34\lib\site-packages\pip\basecommand.py", line 223, in main
  File "C:\Develop\Python34\lib\site-packages\pip\commands\install.py", line 297, in run
  File "C:\Develop\Python34\lib\site-packages\pip\req\req_set.py", line 616, in install
  File "C:\Develop\Python34\lib\site-packages\pip\req\req_install.py", line 721, in uninstall
  File "C:\Develop\Python34\lib\site-packages\pip\req\req_uninstall.py", line 126, in remove
  File "C:\Develop\Python34\lib\site-packages\pip\utils\__init__.py", line 314, in renames
  File "C:\Develop\Python34\lib\shutil.py", line 535, in move
    os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'c:\\develop\\python34\\scripts\\pip.exe'

The workaround python -m pip install -U pip is still useful.

windows auto-locked

Most helpful comment

I am sorry but what is the solution? I am still having the same issue when run "pip uninstall some-package". thanks for instructions.
windows 10.
anaconda3-4.4.0 (Pip version is 9.0.1)
python 3.6.2

All 8 comments

same problem
thanks for the workaround

This looks like a special case duplicate of #1299

I think that this is a special case of a more critical issue I am also having, one that matches this issue's title:

I have a virtual env in D drive, whilst my TEMP folder is in C.

When I use pip uninstall (or pip install -U, which implies an uninstall if the module already exists) I receive the next output:

~~~
Exception:
Traceback (most recent call last):
File "D:\Programs\Python\Python35\lib\shutil.py", line 538, in move
os.rename(src, real_dst)
OSError: [WinError 17] The system cannot move the file to a different disk drive: 'd:\project\_env\lib\site-packages\win32\win32api.pyd' -> 'C:\Users\User\AppData\Local\Temp\pip-av_88tg2-uninstall\project\_env\lib\site-packages\win32\win32api.pyd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Project_env\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "D:\Project_env\lib\site-packages\pipcommandsuninstall.py", line 76, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "D:\Project_env\lib\site-packages\pip\req\req_set.py", line 346, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "D:\Project_env\lib\site-packages\pip\req\req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "D:\Project_env\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
renames(path, new_path)
File "D:\Project_env\lib\site-packages\pip\utils__init__.py", line 267, in renames
shutil.move(old, new)
File "D:\Programs\Python\Python35\lib\shutil.py", line 553, in move
os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'd:\Project_env\lib\site-packages\win32\win32api.pyd'
~~~

It seems that pip is trying to backup the files it's going to replace/remove by using a move crossing drives, that is not supported by Windows.

1299 isn't relevant here (as that's about trying to upgrade a file that's in use).

The traceback points at an "access denied" error in shutil.move. However, this shouldn't be because it's across drives, as @KuttKatrea suggests, as shutil.move supports this (by doing copy-then-delete). From the following line in the traceback, it looks like the delete is failing. An access denied error typically implies that something has the file open, so I'd suggest that maybe you have a Python session running in your virtualenv that uses win32api.

Pip uses pywin32 in the vendored appdirs module, so it may be pip that's holding the file open. If so, then I don't know what we can do, short of raising a feature request on appdirs to force it to not use pywin32, or simply to remove it (I don't honestly see the need to use pywin32, as the ctypes code should work on all Windows systems).

I'm going to close this issue, please reopen it or open a new one if it is still an issue. While I don't have a Windows machine to test this, we are no longer using win32 in appdirs so that should no longer be an issue here.

I am sorry but what is the solution? I am still having the same issue when run "pip uninstall some-package". thanks for instructions.
windows 10.
anaconda3-4.4.0 (Pip version is 9.0.1)
python 3.6.2

On changelog,

10.0.0b1 (2018-03-31)
Display a message to run the right command for modifying pip on Windows (#4490)

by the change, this issue has resolved.
I got a bellow message:

(venv) > pip install -U pip
ERROR: To modify pip, please run the following command:
c:\venv\scripts\python.exe -m pip install -U pip

Thanks!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings