# 如果是用 Miniconda 其中 env_name 是环境名字 python 后面是指定的 python 版本
conda create -n env_name python=3.xx.xx
# 如果不想或不能使用 conda 可以使用 venv
# 这个代码会在指定的路径下创建环境 env_name 也是环境名字
python -m venv /path/env_name
# 需要通过其他命令激活 然后就可以使用 pip 安装
/path/env_name/bin/activate
https://pytorch.org/get-started/locally/
# 测试版 pytorch 下载命令
pip3 install --pre torch torchvision torchaudio --index-url <https://download.pytorch.org/whl/nightly/cu126>
# 清华源 xx 表示你需要安装的库
pip install xx -i [<https://pypi.tuna.tsinghua.edu.cn/simple>](<https://pypi.tuna.tsinghua.edu.cn/simple>)
pip install albumentations opencv-contrib-python jupyter matplotlib lightning wandb einops pandas scikit-learn datasets transformers kornia bitsandbytes peft timm openvino nncf lightgbm triton torchmetrics ultralytics heavyball -i [<https://pypi.tuna.tsinghua.edu.cn/simple>](<https://pypi.tuna.tsinghua.edu.cn/simple>)
#!/bin/bash
# 脚本默认使用 python3,如果需要指定版本,请先用 pyenv 激活
# pyenv shell 3.11.5
# 使用 `set -e` 让脚本在任何命令失败时立即退出,这是一个好习惯。
set -e
ENV_NAME="py"
echo "--- Creating virtual environment: $ENV_NAME ---"
# 使用系统默认的 python3 创建环境
uv venv $ENV_NAME -p python3
# 创建需求文件
echo "--- Generating requirements files ---"
# PyTorch (Nightly) - 只包含包名
cat > requirements.torch.txt << EOL
torch
torchvision
torchaudio
EOL
# Application dependencies - 只包含包名
cat > requirements.app.txt << EOL
# 机器学习/深度学习
scikit-learn
transformers
timm
kornia
# 深度学习辅助
albumentations
einops
torchmetrics
lightning
# 数据处理
pandas
datasets
# 图像处理
opencv-contrib-python
scikit-image
# 数据可视化
matplotlib
seaborn
pyfonts
# MLOps/部署/优化
wandb
triton
# 开发效率/终端工具
jupyter
rich
tqdm
EOL
echo "--- Activating environment and installing packages ---"
# 使用 POSIX 兼容的点号激活
. "$ENV_NAME/bin/activate"
# 使用 uv 安装,将所有选项放在命令行
echo "--- Installing PyTorch (Nightly) ---"
uv pip install --pre \\
--index-url <https://download.pytorch.org/whl/nightly/cu126> \\
-r requirements.torch.txt
echo "--- Installing other application dependencies ---"
uv pip install \\
--index-url <https://pypi.tuna.tsinghua.edu.cn/simple> \\
-r requirements.app.txt
echo "--- Cleaning up requirements files ---"
rm requirements.torch.txt requirements.app.txt
echo "--- Setup complete. Environment '$ENV_NAME' is ready. ---"
echo "To activate it in your current shell, run: source $ENV_NAME/bin/activate"