There is a similar trick.
Install pip in the embedded version:
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Edit pythonXX._pth by adding
Lib
Lib\site-packages
Use pip to install other packages
There is a similar trick.
Install pip in the embedded version:
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Edit pythonXX._pth by adding
Lib
Lib\site-packages
Use pip to install other packages
At least with the latest Python versions (tested on 3.8 and 3.11) this appears to work fine:
Download the Windows embeddable package you need from the official site, and extract it.
PS> Invoke-WebRequest -Uri https://www.python.org/ftp/python/3.11.1/python-3.11.1-embed-amd64.zip -OutFile python-3.11.1-embed-amd64.zip PS> Expand-Archive .\python-3.11.1-embed-amd64.zip PS> cd .\python-3.11.1-embed-amd64Open the
python3xx._pthfile corresponding to your version (e.g.python311._pthfor Python 3.11), and make sure the following import line is uncommented. This will automatically add site directories used by pip to the Python path:# Uncomment to run site.main() automatically import siteIn Powershell this can be automated by running:
PS> Add-Content -Path .\python311._pth -Value 'import site'Download the official pip bootstrap script, e.g. with Powershell:
PS> Invoke-WebRequest -Uri https://bootstrap.pypa.io/get-pip.py -OutFile get-pip.pyRun the downloaded script (make sure you're using the correct Python executable in the current directory
.\):PS> .\python.exe get-pip.py Collecting pip Using cached pip-22.3.1-py3-none-any.whl (2.1 MB) Collecting setuptools Downloading setuptools-66.0.0-py3-none-any.whl (1.3 MB) ---------------------------------------- 1.3/1.3 MB 16.0 MB/s eta 0:00:00 Collecting wheel Using cached wheel-0.38.4-py3-none-any.whl (36 kB) Installing collected packages: wheel, setuptools, pip WARNING: The script wheel.exe is installed in 'C:\Users\xxxx\Downloads\python-3.11.1-embed-amd64\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:\Users\xxxx\Downloads\python-3.11.1-embed-amd64\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-22.3.1 setuptools-66.0.0 wheel-0.38.4Run pip from the
.\Scriptsdirectory:PS> .\Scripts\pip.exe list Package Version ---------- ------- pip 22.3.1 setuptools 66.0.0 wheel 0.38.4 PS> .\Scripts\pip.exe install numpy Collecting numpy Downloading numpy-1.24.1-cp311-cp311-win_amd64.whl (14.8 MB) ---------------------------------------- 14.8/14.8 MB 11.9 MB/s eta 0:00:00 Installing collected packages: numpy WARNING: The script f2py.exe is installed in 'C:\Users\xxxx\Downloads\python-3.11.1-embed-amd64\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 numpy-1.24.1 PS> .\python.exe -c 'import numpy; print(numpy.__version__)' 1.24.1
Even if explicitly stated that the embeddable version of Python does not support Pip, it is possible with care. You need to:
Download and unzip Python embeddable zip file.
In the file
python39._pthor similar, uncomment theimportcommand. Result should look similar to this:python39.zip . import siteDownload get-pip.py to the Python install folder (direct link)
Run
get-pip.py. this installs Pip into theScriptsdirectory:python get-pip.pyRun Pip directly from command line as Pip is a executable program (this example is to install Pandas):
.\Scripts\pip install pandas
You could find more information about this in the Pip issue 4207
how I installed pip into an embeddable python distribution:
- unpack the python embeddable distro archive and cd there
- run
python ./get-pip.py(got here) - EITHER just uncomment string
import siteinside file pythonXX._pth OR copy folders (at least pip) from the newly-created folder Lib/site-packages/ into pythonXX.zip
now it's possible to python -m pip ...