embed python环境快速搭建

📅 2026/7/11 12:09:38 👁️ 阅读次数 📝 编程学习
embed python环境快速搭建

exe包安装python是常用方式,再通过venv模块创建虚拟环境达到隔离效果。
但涉及到分发的项目,不希望每个用户再安装python环境,通过venv创建虚拟环境,再安装依赖。
embed python包可以直接分发给用户,用户开箱即用。

1.下载

官方网站 https://www.python.org/ftp/

包名 python-3.14.6-embed-amd64.zip

2.uncomment site

python314._pth

# Uncomment to run site.main() automatically
import site

3.安装配置pip

get-pip.py
https://bootstrap.pypa.io/get-pip.py
执行

python get-pip.py

配置 pip.ini
在解压后的根目录 手动创建 pip.ini

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn

验证配置生效

python -m pip config list -v

4.安装依赖

python -m pip install -r requirement.txt

5.embed python环境已配好,备份并分发使用。