indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.75k stars 109 forks source link

pip.exe "failed to create process" on Windows 10 #88

Closed joaompinto closed 2 years ago

joaompinto commented 2 years ago

To reproduce, from a Windows 10 system:

curl -LO https://github.com/indygreg/python-build-standalone/releases/download/20210724/cpython-3.9.6-x86_64-pc-windows-msvc-shared-install_only-20210724T1424.tar.gz
mkdir cpython
tar -C cpython -xvf cpython-3.9.6-x86_64-pc-windows-msvc-shared-install_only-20210724T1424.tar.gz
cpython\python\Scripts\pip --version

Results in the following error:

failed to create process.

joaompinto commented 2 years ago

After some research I have that the error is related to the pip-scripts* binary path.

I was able to fix it by changing the first line with the following function:

def fix_pip_scripts():
    scriptsPath = Path(sys.executable).parent.joinpath("Scripts").absolute()
    pip_scripts = scriptsPath.glob("pip*-script.py")
    for script in pip_scripts:
        print(f"Fixing {script}")
        with open(script) as script_file:
            script_data = script_file.readlines()
        script_data[0] = f"#!{sys.executable}\n"
        with open(script, "w") as script_file:
            script_file.writelines(script_data)

Is this something that should be added to the documentation ?

Thanks

silverjam commented 2 years ago

I had issues with pip on Win10 too, but seems related to this: https://github.com/indygreg/python-build-standalone/issues/85

joaompinto commented 2 years ago

I guess you had a problem when using python -m pip, that works out of the box for me with the last release, what does not work is pip.exe :)

indygreg commented 2 years ago

The .py based files in Scripts have disappeared after commit cd2a0ff18b56b5ffd3d57ce0fc43029d33454697. I don't think those were standard files, as the official CPython distributions don't contain them.

Unfortunately, the pip.exe executables still appear to be referencing the build directory. e.g.

c:\dev\src\python-build-standalone\build\python\install>Scripts\pip.exe
Fatal error in launcher: Unable to create process using '"C:\Users\gps\AppData\Local\Temp\python-build-y9tt79xu\out\python\install\python.exe"  "c:\dev\src\python-build-standalone\build\python\install\Scripts\pip.exe" ': The system cannot find the file specified.

This absolute path appears to be embedded in the built binary. We'll have to cajole the generation of these .exe to reference a relative path. I'm unsure if that is trivial. It might be best to delete these executables from the distributions and tell consumers to use python.exe -m pip instead.

joaompinto commented 2 years ago

Removing the binaries and documenting the need to use -m pip would be a reasonable "fix" in my opinion :)