PyTorch离线文档编译方法

创建日期:2025-01-13
更新日期:2025-02-04

编译方法

1、安装必要软件。

sudo apt update
sudo apt install git
sudo apt install python3 -y

2、使用ubuntu下载pytorch项目。

git clone https://github.com/pytorch/pytorch.git

3、创建python虚拟环境。

python -m venv myenv
source ./myenv/bin/activate

4、进入pytorch文档目录。

cd pytorch/docs

5、安装pip包。

pip install -r requirements.txt
pip install torch

6、编译文档。

make html

生成的文档在build/html目录。

常见问题

1、pip install -r requirements.txt报错:git clone ~-~-filter=blob:none ~-~-quiet https:~/~/github.com/pytorch/pytorch_sphinx_theme.git /home/liteng/myenv/src/pytorch-sphinx-theme did not run successfully. exit code: 128

网络问题,可以多试几次。

2、make html报错:ModuleNotFoundError: No module named 'torch'。

没有安装torch包,执行 pip install torch 即可。

3、make html报错:AttributeError: module 'numpy' has no attribute 'bool8'. Did you mean: 'bool'?。

numpy版本问题,执行以下代码即可:pip install numpy==1.26.4

4、make html报错:FileNotFoundError: [Errno 2] No such file or directory: 'katex'

katex版本问题,执行以下代码即可:pip install sphinxcontrib.katex==0.9.0