Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I build PyTorch without using CMake


Can I build PyTorch without using CMake


Building PyTorch without using CMake is not straightforward because CMake is the primary build system used by PyTorch for managing dependencies and compiling the code. However, you can use pre-built binaries or libraries to avoid building from source with CMake.

1. Using Pre-built Binaries: You can download pre-built PyTorch binaries from the official PyTorch website. These binaries are available for various platforms and include both Python and C++ interfaces. For C++ projects, you can use the pre-built libtorch binaries, which are available for CPU and GPU architectures. This approach allows you to integrate PyTorch into your C++ project without needing to build it from source using CMake.

2. Python Installation: If you are primarily interested in using PyTorch with Python, you can install it using pip. This method does not require CMake or any manual compilation:

bash
   pip install torch torchvision
   

This command installs PyTorch and its dependencies without needing to build from source.

3. Building from Source without CMake: While it's not recommended, if you want to avoid CMake entirely, you might consider using a different build system or manually compiling the source code. However, this approach is complex and not well-supported by the PyTorch community. PyTorch's build process is heavily integrated with CMake, making it difficult to bypass without significant effort and expertise.

In summary, while you can't easily build PyTorch without CMake from source, you can use pre-built binaries or install PyTorch via pip for Python projects, which circumvents the need for manual compilation with CMake.

Citations:
[1] https://github.com/pytorch/pytorch/issues/69068
[2] https://github.com/pytorch/pytorch/blob/main/CMakeLists.txt
[3] https://discuss.pytorch.org/t/how-to-compile-binary-with-libtorch-without-cuda/27362
[4] https://pytorch.org/multipy/latest/setup.html
[5] https://discuss.pytorch.org/t/issues-with-building-libtorch-without-python-dependencies/138791
[6] https://stackoverflow.com/questions/52506991/pytorch-not-building-with-cmake-in-developer-console
[7] https://discuss.pytorch.org/t/how-do-i-to-create-a-new-project-in-c-to-run-libtorch-without-cmake/79046
[8] https://discuss.pytorch.org/t/help-how-to-force-pytorch-build-from-source-on-older-cuda-gpu/184139