pip brings harcoded python 3.8 path (doesn't run with any newer python version)
See original GitHub issueDescription
Currently, we’re on python 3.9.7. If you check the install options in the official python installer, it already comes with pip.
The problem is you can’t run pip on any fresh install of Python 3.9.x, you’ll get the error:
Fatal error in launcher: Unable to create process using '"c:\program files\python38\python.exe" "C:\Program Files\Python38\Scripts\pip.exe" --version': The system cannot find the file specified.
As it turns out, the internet (e.g StackOverflow) is now laden with complaints about this issue. Many people assume it’s related to PATH/environment varibles misconfiguration, but it has nothing to do with it.
I was convinced it was some issue with pip itself, because it was looking for the Python 3.8, something I never installed on my PC, as well as it was looking into the path where pip itself was installed.
As it turns out, I opened the pip.exe binary found under C:\Program Files\Python38\
in a hex editor, found the aforementioned path there and changed it to my actual Python 3.9 path and now it works as it should.
Expected behavior
pip should read Python’s path from my enviroment variables, rather than bringing a hardcoded Python 3.8 path (which btw isn’t even the default Python 3.8 install path)
pip version
21.2.4
Python version
3.9.7
OS
Windows 10 x64 2004
How to Reproduce
- Download Python 3.9.x from https://www.python.org/
- Install Python 3.9.7
- Open cmd/powershell and try invoking the command
pip
Output
Fatal error in launcher: Unable to create process using '"c:\program files\python38\python.exe" "C:\Program Files\Python38\Scripts\pip.exe" --version': The system cannot find the file specified.
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)
Top GitHub Comments
This is by design. When an executable wrapper is contained (either for pip, or for any other package that pip installs) we hard code the exact path to the Python interpreter that the package is installed into. This is to ensure that the command is run using the Python interpreter that has the necessary dependencies installed.
If you use the executable wrapper for pip (rather than the recommended approach of using
py -m pip
) then you should always use the wrapper installed in the Python installation you want to run pip against.Actual problem is that on Windows pip embeds full paths into scripts (pip.exe is a compiled script itself).
See #10700