pypa / get-pip

Helper scripts to install pip, in a Python installation that doesn't have it.
https://bootstrap.pypa.io/pip/
MIT License
738 stars 293 forks source link

[bug] pip not working on python embeddable package #217

Closed shdwmtr closed 2 months ago

shdwmtr commented 2 months ago

When attempting to install pip with get-pip on the embeddable package of python, it doesn't seem to work properly.

Steps to reproduce:

$url = "https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-win32.zip"
$outfile = "python-3.11.8-embed-win32.zip"
$extractDir = "C:\path\to\extract\directory"
Invoke-WebRequest -Uri $url -OutFile $outfile
Expand-Archive -Path $outfile -DestinationPath $extractDir
Remove-Item $outfile

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
C:\path\to\extract\directory\python.exe get-pip.py

Fixes, but not desirable

 

Output:

PS C:\Program Files (x86)\Steam\ext\data\cache> ./python get-pip.py
Collecting pip
  Using cached pip-24.1.1-py3-none-any.whl.metadata (3.6 kB)
Collecting setuptools
  Using cached setuptools-70.2.0-py3-none-any.whl.metadata (5.8 kB)
Collecting wheel
  Using cached wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
Using cached pip-24.1.1-py3-none-any.whl (1.8 MB)
Using cached setuptools-70.2.0-py3-none-any.whl (930 kB)
Using cached wheel-0.43.0-py3-none-any.whl (65 kB)
Installing collected packages: wheel, setuptools, pip
  WARNING: The script wheel.exe is installed in 'C:\Program Files (x86)\Steam\ext\data\cache\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pip.exe, pip3.11.exe and pip3.exe are installed in 'C:\Program Files (x86)\Steam\ext\data\cache\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-24.1.1 setuptools-70.2.0 wheel-0.43.0

PS C:\Program Files (x86)\Steam\ext\data\cache> ./python
Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 21:52:07) [MSC v.1937 32 bit (Intel)] on win32
>>> import site
>>> print(site.getsitepackages())
['C:\\Program Files (x86)\\Steam\\ext\\data\\cache', 'C:\\Program Files (x86)\\Steam\\ext\\data\\cache\\Lib\\site-packages']
>>>

PS C:\Program Files (x86)\Steam\ext\data\cache> ./Scripts/pip.exe
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Program Files (x86)\Steam\ext\data\cache\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
PS C:\Program Files (x86)\Steam\ext\data\cache> ./python -m pip
C:\Program Files (x86)\Steam\ext\data\cache\python.exe: No module named pip
PS C:\Program Files (x86)\Steam\ext\data\cache>
shdwmtr commented 2 months ago

Fixed by uncommenting import site in pythonxxx._pth in the embeddable package