Cannot Build from Source on Linux due to 'File name too long' error during Git clone

I am attempting to build PyTorch from source code on a standard Linux environment, but the git clone operation fails during the file checkout stage due to the “File name too long” error. This prevents a full clone and subsequently breaks the build process.

I ran the command:

git clone https://github.com/pytorch/pytorchcd pytorch
# if you are updating an existing checkout
git submodule sync 
git submodule update --init --recursive

And I got this output (this filname is one example out of many):

(pythorch) davir@davir-System-Product-Name:~$ git clone -c core.longpaths=true https://github.com/pytorch/pytorch
Cloning into 'pytorch'...
remote: Enumerating objects: 1170914, done.
remote: Counting objects: 100% (1208/1208), done.
remote: Compressing objects: 100% (513/513), done.
remote: Total 1170914 (delta 1070), reused 697 (delta 695), pack-reused 1169706 (from 4)
Receiving objects: 100% (1170914/1170914), 1.08 GiB | 33.21 MiB/s, done.
Resolving deltas: 100% (934405/934405), done.
error: unable to create file test/compiled_autograd_skips/TestNestedTensorSubclassCPU.test_jagged_op_different_output_shape_dim_mean_keepdim_True_requires_grad_False_components_require_grad_False_cpu_float32: File name too long

I tried also :

git clone -c core.longpaths=true https://github.com/pytorch/pytorch

But got the same erros.
How can I solve this?

I’m not familiar with your setup, but are you able to clone the repo into another folder that is not your home? If so, I guess you might have encrypted the ~ folder which could increase the file path lengths and could then run into your OS limit.

@ptrblck Thank you. I am using Linux Mint 22. I tried clone the reo into folder out of home folder and it worked!

1 Like