Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"pip.exe install --upgrade pip" fails on Windows (trying to move/delete running pip.exe) #3804

Closed
blep opened this issue Jun 19, 2016 · 6 comments
Labels
auto-locked Outdated issues that have been locked by automation OS: windows Windows specific

Comments

@blep
Copy link

blep commented Jun 19, 2016

  • Pip version: 7.1.0
  • Python version: Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
  • Operating System: Windows-10-10.0.10586-SP0 (<= platform.platform())

Description:

Pip upgrade using pip.exe install --upgrade pip fails and leave python pip broken (pip.exe remains, but pip-script.py was deleted).

AFAIK upgrade fail because it is trying to delete pip.exe which is currently running. IMHO for a pip upgrade this step should be skipped as it will point to the same pip-script.py after re-install.

Fixing broken pip:

The broken pip caused by the failed upgrade can be fixed by running:

easy_install pip

What I've run:

Notes that below I run the command Scripts\pip.exe install --upgrade pip to make the issue more obvious. Typing pip install --upgrade pip executes the same command.

shutil.move is trying to copy/delete the executable as it is on a different drive than the TEMP directory.

    e:\venv_pip_upgrade>Scripts\activate.bat
    (venv_pip_upgrade) e:\venv_pip_upgrade>Scripts\pip.exe install --upgrade pip
    You are using pip version 7.1.0, however version 8.1.2 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    Collecting pip
      Using cached pip-8.1.2-py2.py3-none-any.whl
    Installing collected packages: pip
      Found existing installation: pip 7.1.0
        Uninstalling pip-7.1.0:
    Exception:
    Traceback (most recent call last):
      File "C:\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: 'e:\\venv_pip_upgrade\\scripts\\pip.exe' -> 'C:\\Users\\Zark\\AppData\\Local\\Temp\\pip-ydctswjh-uninstall\\venv_pip_upgrade\\scripts\\pip.exe'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\basecommand.py", line 223, in main
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\commands\install.py", line 299, in run
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_set.py", line 640, in install
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_install.py", line 726, in uninstall
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_uninstall.py", line 125, in remove
      File "e:\venv_pip_upgrade\lib\site-packages\pip-7.1.0-py3.5.egg\pip\utils\__init__.py", line 314, in renames
      File "C:\Python35\lib\shutil.py", line 553, in move
        os.unlink(src)
    PermissionError: [WinError 5] Access is denied: 'e:\\venv_pip_upgrade\\scripts\\pip.exe'

    (venv_pip_upgrade) e:\venv_pip_upgrade>Scripts\pip.exe install --upgrade pip
    Cannot open e:\venv_pip_upgrade\Scripts\pip-script.py
@jamadden
Copy link
Member

The usual workaround to this is python -m pip install --upgrade pip.

@pfmoore
Copy link
Member

pfmoore commented Jun 19, 2016

And just to clarify, this is a limitation of Windows (you cannot replace a running executable) rather than of pip.

@RajeshRajchal
Copy link

And when running the command -m pip install --upgrade pip, make sure you are running command as administrator.

find the "Command Prompt
Right click on "Command Prompt"
Run as Administrator

@xavfernandez
Copy link
Member

Duplicate of the old #1299

@xavfernandez xavfernandez added the OS: windows Windows specific label Jul 6, 2016
rqelibari added a commit to rqelibari/sirup that referenced this issue Mar 8, 2017
Error did not disappear after having a pip install script. According to
pypa/pip#3804 one just needs to update pip.
jedie added a commit to jedie/bootstrap_env that referenced this issue Mar 12, 2018
* work-a-round for: pypa/pip#3804
* use full path to ADMIN_FILE_NAME
asfaltboy pushed a commit to asfaltboy/GitSavvy that referenced this issue Mar 19, 2018
@isan0786
Copy link

For me this command works.->py -m pip install -U pygame --user
But first, make sure you properly configure your environment variables.
This tutorial http://www.aaronstannard.com/how-to-setup-a-proper-python-environment-on-windows/ will help you how to setup environment variables for python, make sure you do it correctly only step 2 ,no need to do any other steps from this tutorial, now you can follow my steps that were listed below. I will assume that you have already installed python in your computer

Step1

Search for cmd and Right click on cmd and do run as administrator.

Step2

Run the command, py -m pip install -U pygame --user, but before you run this command first of all make sure you configure your environment variables properly.

Step3

Type python in command prompt, this will take you to the python command line which will look like this ">>>".If not then you have a problem with your system variables.

Step4

Make sure you are in python command line and then type import pygame,and after this press ctrl+z and enter that will take you out from python command line.

Step5

Make sure you are not in python command line and then run this command py -m pygame.examples.aliens,if the game starts then congrats you are done.

ionutbalutoiu added a commit to ionutbalutoiu/dcos that referenced this issue May 22, 2018
This pip upgrade upgrade will fail on Windows.

The following issue explains the situation and the workaround
proposed: pypa/pip#3804
ionutbalutoiu added a commit to ionutbalutoiu/dcos that referenced this issue May 22, 2018
* The directory dcos_build_venv must be deleted only if it already exists.
* Fix pip upgrade. The following issue explains the situation and the
  proposed workaround proposed: pypa/pip#3804
@lock
Copy link

lock bot commented Jun 2, 2019

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.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation OS: windows Windows specific
Projects
None yet
Development

No branches or pull requests

6 participants