Packaging: How do a build Python PyTorch from a `-DBUILD_PYTHON=OFF`, library-only build?

I have packaged a library-only (non-Python) build of PyTorch (-DBUILD_PYTHON=OFF passed to cmake) for Slackware (using this SlackBuild), but now I’d like to make another Slackware package for Python PyTorch.

How do a build Python PyTorch? It seems -DBUILD_PYTHON=ON would have created all the necessary files, but when I run python3 install --root=$PKG, it complains that I’m not in a git repo; I downloaded pytorch-v2.3.0.tar.gz to make the library-only package.

It actually did build the site-package files. I just needed to manually move them to the $PKG by adding these lines to the SlackBuild (right before cd ..):

  mkdir -p $PKG/usr/lib$LIBDIRSUFFIX/python3.11
  mv tmpxxx/usr/lib/python3.11/site-packages $PKG/usr/lib$LIBDIRSUFFIX/python3.11

But the problem here is that that site-packages directory doesn’t have any files or anything. Why didn’t cmake make them? Must I use (which requires I be in a git directory)?

I tried using in a git clone:

git clone --recursive

In the SlackBuild, I used this instead (paths specific to my CUDA install):

CUDA_PATH=/usr/share/cuda \
CUDAHOSTCXX=/home/geremia/gcc-11/usr/bin/gcc \
CUDNN_LIBRARY=/usr/share/cuda/lib64/ \
NVTOOLSEXT_PATH=/usr/lib64/ \
python develop

But ran into errors I didn’t have in the CMake build. I wish I didn’t have to use at all to build the Python bindings.

I needed to use Ninja, run build with the --cmake-only flag, and manually install Python site-package stuff, as described here.