跳到主要内容

Python

UV

纯粹, 快

1. 安装 UV

完成后使用 uv --version 查看

Windows
winget install --id=astral-sh.uv -e
Linux
wget -qO- https://astral.sh/uv/install.sh | sh

2. 安装 Python

uv python install 3.12

3. 初始化项目

uv init --name
初始化脚本
uv init --script your_script.py

4. 添加依赖

uv add pandas openpyxl
添加脚本依赖
uv add --script your_script.py "pandas" "openpyxl"

5. 全局工具安装

uv tool install nuitka

6. 切换 Python 版本

uv run --python 3.11 your_script.py

7. 运行外部工具

uvx --from "nuitka[onefile]" nuitka.cmd \
--standalone \
--onefile \
--windows-icon-from-ico=logo.ico \
-o your_app.exe \
main.py
提示

[] 指定可选依赖, 业界称 Extras, 此处指定的是调用压缩插件

Conda

针对科学计算做了优化, 解决了C/C++依赖问题, 比较重

channel

  • defaults main/msys2/r 官方版, 更稳定
  • conda-forge 社区版, 包更丰富, 使用时 -c conda-forge 指定

Miniforge

  • mamba 替代 conda 命令, 用 c++ 实现

命令行工具打包

conda create -n env_name python=3.11
conda activate ENVNAME
pip install pyinstaller
pyinstall --onefile yourscript.py