Closed Awful-Leo closed 2 years ago
Hi! IMHO this should be done for all packages, i.e. if install will fail then after uninstall we should have something to revert to. For the permission case only GH-6762 might fix it.
When uninstalling pip, temporarily stores the old pip to a temp folder maybe. If the installing of the newer version is successful, delete the temp file; if not, roll back and reinstall the original version.
pip uninstall
does this already. Please provide the steps for reproductions along with the output of the commands, to help diagnose why that's not happening in your case.
Note that not all of pip's developers have access to the all OSes, so the output of the steps, are especially relevant and helpful. :)
Also,
update pip in cmd with "pip install pip -U"
The recommended way of updating pip on Windows is py -m pip install -U pip
. If you do pip install -U pip
you will get a permission error because the install can't update the running pip.exe
wrapper.
This may or may not be relevant to the issue you're reporting, but it would be helpful if you could update your description of how to reproduce the issue so that it uses the supported approach.
OK, I just did it again on the newly updated windows 10 (10.0.19041) with python-3.8.2-amd64.exe.
Here's what happened after the installation from powershell.
PS C:\Users\Leo> pip -V
pip 19.2.3 from c:\program files\python38\lib\site-packages\pip (python 3.8)
PS C:\Users\Leo> pip install pip -U
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/43/84/23ed6a1796480a6f1a2d38f2802901d078266bda38388954d01d3f2e821d/pip-20.1.1-py2.py3-none-any.whl (1.5MB)
|████████████████████████████████| 1.5MB 2.2MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'c:\\program files\\python38\\lib\\site-packages\\pip-19.2.3.dist-info\\entry_points.txt'
Consider using the `--user` option or check the permissions.
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
PS C:\Users\Leo>
so I opened another powershell window with admin privilege.
PS C:\WINDOWS\system32> pip install pip -U
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/43/84/23ed6a1796480a6f1a2d38f2802901d078266bda38388954d01d3f2e821d/pip-20.1.1-py2.py3-none-any.whl (1.5MB)
|████████████████████████████████| 1.5MB 2.2MB/s
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
Successfully uninstalled pip-19.2.3
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒绝访问。: 'C:\\Users\\Leo\\AppData\\Local\\Temp\\pip-uninstall-17mx4r60\\pip.exe'
Consider using the `--user` option or check the permissions.
PS C:\WINDOWS\system32> pip install pip -U
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already up-to-date: pip in c:\program files\python38\lib\site-packages (20.1.1)
OK...the update worked although there were some errors, and I'm not sure which step I did different from the last one.
I'll try to reproduce the issue again on my other laptop at office next week.
Thank you all again.
@pfmoore This looks like the check for "is this affecting pip" needs to be improved, since we've had a change in how pip uninstall works? I'm a fair bit out of my water here though, so I'll defer to you and @uranusjr on this. :)
At this point maybe we should just add a check in install
and uninstall
, and hard error if pip
is listed in the command line. (Clarify: I want to do this for all operating systems so tutorials/articles would be motivated to update.)
Uhm... I think I see the issue here:
The conditional here is wrong. :)
Just had another try. OS: Windows 10 (Ver 1607 14393.3686) Enterprise Edition 2016 LTSB
Python:python-3.8.3-amd64.exe(downloaded from python.org)
--user
option or check the permissions.PS C:\Users\Leo Wang> pip install pip -U
Traceback (most recent call last):
File "d:\program files\python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\program files\python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\Program Files\Python38\Scripts\pip.exe__main__.py", line 5, in
Pheeeeew! This is exactly what I was trying to let you guys when opening this issue.
@pfmoore, the reason why I'm using this very "pip install pip -U" is that I was trying to update the pip source with a mainland mirror in China, so I referred to the tuna page (https://mirrors.tuna.tsinghua.edu.cn/help/pypi/) which is owned and maintained by Tsinghua University. And it says to change the default mirror to tuna, the right way is to do these: ####################### pip install pip -U pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple #######################
Anyway, please see if there's anything that can be bettered to avoid future users from stepping into this situation.
Thank you all.
Now the only way to rescue my python env is to download "pip-20.1.1.tar.gz " from the following page: pypi.org/project/pip/#files and extract it and re-install pip with python setup.py install.
A much better approach would be to download and run https://bootstrap.pypa.io/get-pip.py.
@Awful-Leo As @pfmoore noted, on Windows, you should do py -m pip install pip -U
and not pip install pip -U
. As I noted above, the conditional that is supposed to prevent users from doing pip install pip -U
is incorrect and needs to be fixed.
As I noted above, the conditional that is supposed to prevent users from doing
pip install pip -U
is incorrect and needs to be fixed.
So is the conditional flipped and should be modifying_pip = pip_req.satisfied_by is not None
, since if we are modifying pip, and pip is already installed, pip_req.satisfied_by
will not be None?
I don't know if it's directly related, but a student of mine encontered something like this, but in a venv:
D:\sup internet\python\oeis>python -m venv .venv && ".venv\Scripts\activate.bat"
(.venv) D:\sup internet\python\oeis>pip --version
pip 19.2.3 from d:\sup internet\python\oeis\.venv\lib\site-packages\pip (python 3.8)
(.venv) D:\sup internet\python\oeis>pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Accès refusé: 'd:\\sup internet\\python\\oeis\\.venv\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.
"Accès refusé" mean "Access denied", but as it's in a freshly created venv, the pip.exe was freshly created with the same user and same session, and also freshly deleted by the uninstall, so it's probably not exactly an acess right error.
@JulienPalard On Windows, the OS locks a running executable so it can't be modified or deleted. So pip install --upgrade pip
can't upgrade the pip.exe
file, and you get "Access denied". The message is correct - access is denied because you're trying to modify a running exe.
The fix is, as per the recommendation in the documentation, to use the longer form py -m pip install --upgrade pip
, which runs Python directly, not via the wrapper. So the wrapper isn't locked and the upgrade can replace it.
The discussion here is mostly about whether we can improve the error to explain what's happened better. It's annoyingly difficult to do so 🙁
Thanks @pfmoore for this clear clarification!
IIRC, after trying the pip install --ugprade pip
, the student did no longer have pip
at all in its venv, which is a bit strange, I understand pip was unable to update it in place, but why was it able to remove it?
The student had hard time figuring this out, as "the pip command" would continue working after the deletion of .venv/Scripts/pip.exe
: Windows was finding the "global pip", next on the PATH, itself trying to install things outside of the venv.
Enhancing the message would be a good start, but if it still delete pip.exe
it may be a bit hard for a newcomer to recover?
The pip.exe shouldn't be getting deleted, unless Windows has started doing something new.
Not entirely on topic, but I would suggest recommending newcomers to avoid pip.exe
(and pip
on POSIX) entirely in favour of python -m pip
(or even better on Windows, py -m pip
). The python
executable is not likely to be removed (and the environment would be in big trouble if it is), and would work in all cases that the pip
executable works. It also avoids pip install -U pip
from breaking the workflow.
Environment
Description
Expected behavior
When uninstalling pip, temporarily stores the old pip to a temp folder maybe. If the installing of the newer version is successful, delete the temp file; if not, roll back and reinstall the original version.
How to Reproduce
Follow the above.