Windows 11 - Trying to install Layout Parser package - fails with error on filename long more than 260 characters long

I am trying to run the following command:
pip install layoutparser torchvision && pip install “git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2”

Failure message is:
Allowing ninja to set a default number of workers… (overridable by setting the environment variable MAX_JOBS=N)
ninja: error: Stat(C:/Users/win10/AppData/Local/Temp/pip-install-4zl39kfo/detectron2_fdca3b3eb0be498b97348507fa457fcb/build/temp.win-amd64-cpython-310/Release/Users/win10/AppData/Local/Temp/pip-install-4zl39kfo/detectron2_fdca3b3eb0be498b97348507fa457fcb/detectron2/layers/csrc/ROIAlignRotated/ROIAlignRotated_cpu.obj): Filename longer than 260 characters
Traceback (most recent call last):
File “C:\Users\win10\AppData\Roaming\Python\Python310\site-packages\torch\utils\cpp_extension.py”, line 2104, in _run_ninja_build
subprocess.run(
File “C:\Program Files\Python310\lib\subprocess.py”, line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command ‘[‘ninja’, ‘-v’]’ returned non-zero exit status 1.

I have already set flag in windows setup to enable long file name.

Can anyone help what is the issue here?

Thanks for help.

You need to change a Windows setting. See filesystems - How to allow long paths in Windows (longer than 260 characters) - Super User

Hi Barry Scott,

I tried the solution but problem still persists.

Is there work around in this case kindly let me know.

Since this is build stage is there a way to breakdown PIP steps and do manually the build phase or something of that sort, if you know or anyone knows, then kindly revert.

Thanks in advance.

You need to make sure that you are using a new enough version of ninja: Should support filename longer than 260 characters · Issue #1900 · ninja-build/ninja · GitHub

Hi Cornelius,

My current version of ninja is 1.11.1 and python 3.10.5.
Latest available is 1.12.1.
I do not know how to upgrade just ninja.
Can you help?

For all facing this kind of problem of installing detectron2 (which was giving filename more than 260 char issue) - may try this which solved problem for me:

from this page - https://detectron2.readthedocs.io/en/latest/tutorials/install.html:

python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu113/torch1.10/index.html

I ran this command and my detectron2 got installed and i am able to go further into LayoutParser.

Thanks guys for supporting.

This can be closed now for me at least. Though main issue was not solved (using ninja thru pip installation but my aim was to use layout parser which required this and that is solved.)