Skip to content

pip should not destroy instead of upgrade itself on Windows #9395

Closed
@chrullrich

Description

@chrullrich

Environment

  • pip version: Any
  • Python version: Any
  • OS: Windows

Description
pip upgrade pip in a venv on Windows will inevitably end in failure to delete the pip.exe wrapper, which is a running process. The next line of output uselessly suggests using --user. The correct approach is to run python -m pip install -U pip instead, but the user is not told this, and at the time of the error the pip installation is already gone anyway.

There are two ways to recover, the faster and far less discoverable one is python -m ensurepip, the other is to nuke the venv and start over.

Upgrading pip in the same way in a system-wide installation also throws the error, but appears to successfully upgrade itself first. I suspect it upgrades the Python bits of itself first and only then fails to recreate the executable wrapper.

Expected behavior
pip should probably do the same in a venv that it does in the system-wide installation, i.e. upgrade its innards first, then fail to update the executable wrapper (because it is somewhat version-independent). If that is not possible, at least it should not uninstall (most of) itself before failing, but exit early and with a comprehensible error message that points out the correct command to run.

(Better yet, it should re-run itself using the correct command line, but that interferes with returning the correct exit code. Oh, exec(), how we miss you.)

How to Reproduce

py -m venv venv
venv\scripts\activate
pip install -U pip

Output:

Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\\daten\\venv\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions