'How are the executables in <python_dir>\python-X.X.X\scripts created?

When I install a package via pip (on Windows), e.g. pip, one or more Windows executables are created in the scripts directory.

> PowerShell -NoProfile -ExecutionPolicy -Command "Invoke-WebRequest -Uri 'https://bootstrap.pypa.io/get-pip.py' -OutFile 'get-pip.py'" 
> python get-pip.py

Collecting pip
  Using cached pip-21.2.4-py3-none-any.whl (1.6 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-21.2.4

> dir ..\python-3.8.5\scripts\pip*.exe
 Volume in drive C has no label.
 Volume Serial Number is 1837-4411

 Directory of \python\python-3.8.5\scripts

09/30/2021  08:18 AM            97,151 pip.exe
09/30/2021  08:18 AM            97,151 pip3.8.exe
09/30/2021  08:18 AM            97,151 pip3.exe
09/29/2021  03:52 PM            97,093 pipdeptree.exe
               4 File(s)        388,546 bytes

pip.exe, pip3.exe, and pip3.8.exe all look to be something kind of py2exe-ish with a Python script embedded in the executable.

What is auto-creating these executables?

The embedded script uses a shebang that has a hardcoded path to the python executable. What I intend as a portable Python distribution is being hosed by this hardcoded path (rather than just specifying python without a path).

Details which may or may not matter

Is there a way to tell pip (or whatever is creating these wrapped executables) to behave differently in this regard?



Solution 1:[1]

These files are created using py2exe whose configurations can be found in setup.py file of the project.

Refer this link for more information: https://python101.pythonlibrary.org/chapter40_py2exe.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dmdhrumilmistry