Skip to content

Instantly share code, notes, and snippets.

@Postrediori
Last active October 7, 2023 17:38
Show Gist options
  • Save Postrediori/ee8fc61acf1c6a1d8acfe7bff8123343 to your computer and use it in GitHub Desktop.
Save Postrediori/ee8fc61acf1c6a1d8acfe7bff8123343 to your computer and use it in GitHub Desktop.
Configure Python Embeddable package for Windows

Python Embeddable

Introduction

This article describes how to add pip, install custom modules and use an interpreter form the embeddable package via batch files.

Download Python Embeddable

  • Navigate to https://www.python.org/downloads/
  • Scroll to Python releases by version number section and choose Download for a required version
  • Select Windows embeddable package for a desired architecture

Install pip

Download get-pip.py script via curl:

curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Alternativelly, download the script manually (from https://bootstrap.pypa.io/get-pip.py) and copy it to Python folder (check https://pip.pypa.io/en/stable/installation/)

Run the script to download pip binaries and scripts:

python get-pip.py

Open config file pythonXX._pth and append the fillowing paths to lookup folder list:

Lib
Lib\site-packages

Now it is possible to run pip for installation of required modules to the embeddable directory.

Use the configured environment

In order to use the configured embedded environment in batch scripts, create a bat file pythonenv.bat in the package directory:

set PYTHON_DIR=%~dp0
set PATH=%PYTHON_DIR%;%PYTHON_DIR%/Scripts;%PATH%

Use pythonenv.bat in a way similar to VsDevCmd.bat from Visual Studio

call python-embeddable\pythonenv.bat
python -m pyserial

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment