question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Obscure error message when installing wheels with long filenames on Windows with LongPathsEnabled set to 0

See original GitHub issue

Description

As documented in our troubleshooting guide, some Windows users experience an obscure error message such as:

C:\Users\username>C:\Users\username\AppData\Local\Microsoft\WindowsApps\python.exe -m pip install scikit-learn
Collecting scikit-learn
...
Installing collected packages: scikit-learn
ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\username\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python37\\site-packages\\sklearn\\datasets\\tests\\data\\openml\\292\\api-v1-json-data-list-data_name-australian-limit-2-data_version-1-status-deactivated.json.gz'

https://scikit-learn.org/stable/install.html#error-caused-by-file-path-length-limit-on-windows

This happens because under Windows, file paths are limited to 260 characters by default.

Expected behavior

When such an error OSError or EnvironmentError with No such file or directory, parse the file path and check if its length could explain the problem.

If this is the case, enrich the error message to point the user to use regedit to set LongPathsEnabled to 1 as we do in the scikit-learn documentation linked above.

pip version

unknown

Python version

does not matter

OS

Windows

How to Reproduce

I suppose it’s possible to create a venv into a deeply nested folder with more than 200 characters and then install wheel package with long filenames in it (pip install scikit-learn==0.24.2 should do).

I am not 100% sure because I have no Windows machine handy.

Output

See above.

Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
uranusjrcommented, Jun 7, 2021

Unfortunately there really isn’t a good solution to this. Windows emits FileNotFoundError for a ton of things, and the path length limit is only one of it. There really isn’t a way to realiably pinpoint the reason. The best pip can do IMO would be to do a len() and suggest maybe you need to enable long paths when the result is over the limit.

2reactions
uranusjrcommented, Jun 8, 2021

@MohsenAAkeel Use this instead

from pip._internal.utils.compat import WINDOWS
Read more comments on GitHub >

github_iconTop Results From Across the Web

Long paths not working in windows 2019 - Microsoft Q&A
Go to Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> Filesystem, then enable the Enable Win32 long ...
Read more >
How To Fix Destination Path Too Long [2022] - YouTube
Fix Destination Path Too Long Error In Windows 10/8/7.If you've ever seen this issue, it was probably a simple fix for you.
Read more >
python - LongPathsEnabled feature doesn't seem to work
Okay guys I have solved the problem with tensorflow installation by downgrading Python to version 3.7. But the issue with CreateFile2 is ...
Read more >
Windows 10 Long File Names - Super User
That said, often the issue is an excessively long path, i.e. drive + full file path + filename longer than 260 characters. You...
Read more >
LongPathsEnabled Setting ignored on Windows Server 2016
I activated the respective local group policy setting (Computer Config -> Administrative Templates -> System -> Filesystem -> Enable Win32 long ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found