MirrorYuChen
MirrorYuChen
Published on 2025-04-14 / 54 Visits
0
0

Python开发环境搭建二三事

1.使用阿里云安装pytorch

  • (1) 在pytorch官网上查找待安装版本torch的安装命令,例如:
>> pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu118
  • (2) 修改为阿里云地址:
# 1.cuda版本11.8,pytorch版本2.1.2
>> pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 -f https://mirrors.aliyun.com/pytorch-wheels/cu118
# 2.cuda版本12.4,pytorch版本2.5.1
>> pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 -f https://mirrors.aliyun.com/pytorch-wheels/cu124/

2.cuda环境搭建安装

  • (1) 第一种方法:直接装驱动
>> wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
>> sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
>> wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
>> sudo dpkg -i cuda-repo-ubuntu2204-11-8-local_11.8.0-520.61.05-1_amd64.deb
>> sudo cp /var/cuda-repo-ubuntu2204-11-8-local/cuda-*-keyring.gpg /usr/share/keyrings/
>> sudo apt-get update
>> sudo apt-get -y install cuda
  • (2) 第二种方法:拉一个cuda的docker
>> sudo docker pull nvidia/cuda:12.4.0-devel-ubuntu22.04  

3.安装软件手动设置源

  • (1) 阿里源:https://mirrors.aliyun.com/pypi/simple
  • (2) 清华源:https://pypi.tuna.tsinghua.edu.cn/simple/
  • (3) 中科大源:http://pypi.mirrors.ustc.edu.cn/simple/

​ 第一种可以直接设置全局的pip源:

>> pip config set global.index-url https://mirrors.aliyun.com/pypi/simple

​ 也可以设置单次的安装源:

>> pip install opencv-python -i https://mirrors.aliyun.com/pypi/simple

4.hugging face模型下载

  • (1) 安装huggingface-cli工具
# 1.安装完整版huggingface_hub包,包含该工具
>> pip install -U huggingface_hub
# 2.也可以指定安装cli工具
>> pip install -U "huggingface_hub[cli]"
  • (2) 设置下载镜像
>> vim ~/.zshrc
export HF_ENDPOINT="https://hf-mirror.com"
>> source ~/.zshrc
  • (3) 下载模型
# 1.指定下载文件列表
>> huggingface-cli download <项目名> <待下载文件列表> --local-dir <下载文件保存路径>
# 2.直接下载全部
>> huggingface-cli download --resume-download <项目名> --local-dir <下载文件保存路径>
# 3.还可以通过--exclude来指定一些忽略项
>> huggingface-cli download --resume-download <项目名> --local-dir <下载文件保存路径> --exclude "*.git*" "README.md" "docs"

​ 例如:

# 1.指定下载文件列表
>> huggingface-cli download IndexTeam/IndexTTS-1.5 \
  config.yaml bigvgan_discriminator.pth bigvgan_generator.pth bpe.model dvae.pth gpt.pth unigram_12000.vocab \
  --local-dir checkpoints
# 2.直接下载全部
>> huggingface-cli download --resume-download Wan-AI/Wan2.1-I2V-14B-480P --local-dir Wan2.1-I2V-14B-480P
# 3.忽略一些选项下载
>> huggingface-cli download KwaiVGI/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"

5.kaolin库安装

  • (1) 最新版本安装命令:
>> pip install kaolin==0.17.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-{TORCH_VER}_cu{CUDA_VER}.html
  • 例如:
>> pip install kaolin==0.17.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.0.1_cu118.html

​ 服务器上有可能没办法翻墙,可以直接打开对应链接地址,然后下载对应whl包上传服务器安装即可。

参考资料


Comment