实验环境配置

基础安装配置

Anaconda(或 Miniconda

按官网文档下载安装1

创建新的 Python 环境

打开命令行终端 Anaconda Prompt,并输入以下代码:

conda create --name ai
conda activate ai
# CPU, Linux
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# CPU, Windows/Mac
pip3 install torch torchvision
python -c "import torch; print(f\"CUDA available? {torch.cuda.is_available()}\"); print(torch.rand(5, 3));"

FAQ

Good Practices

注意:安装路径不使用带有中文或空格的目录

PyTorch

Q: Python complained: “No module named ‘torch’”, but I followed exactly the official instructions

Usually a false alarm: restart the terminal. If the error persists: try lower python versions conda create --name ai python=3.9, or write to the official maintainers.

Quickstart

See: Quickstart @ pytorch.org3.


  1. https://www.anaconda.com/docs/getting-started/installation↩︎

  2. https://pytorch.org/get-started/locally/↩︎

  3. https://pytorch.org/tutorials/beginner/basics/quickstart_tutorial.html↩︎