Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
ogrisel opened this issue Jun 7, 2021 · 8 comments
Labels
C: error messages Improving error messages good first issue A good item for first time contributors to work on type: feature request Request for a new feature

Comments

@ogrisel
Copy link
Contributor

ogrisel commented Jun 7, 2021

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

@ogrisel ogrisel added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jun 7, 2021
@uranusjr
Copy link
Member

uranusjr commented 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.

@ogrisel
Copy link
Contributor Author

ogrisel commented Jun 7, 2021

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.

+1 for doing a len() on the exception error message (since it includes the file path).

@uranusjr uranusjr added good first issue A good item for first time contributors to work on C: error messages Improving error messages type: feature request Request for a new feature and removed S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Jun 7, 2021
@uranusjr
Copy link
Member

uranusjr commented Jun 7, 2021

For aspiring contributors: This needs to be handled in the except OSError block in InstallCommand.run() (pip/_internal/commands/install.py). The function is a monster, so some refactoring en passant may make sense as well.

@OBITORASU
Copy link
Contributor

OBITORASU commented Jun 8, 2021

except OSError as error:
    show_traceback = (self.verbosity >= 1)

    message = create_os_error_message(
        error, show_traceback, options.use_user_site,
    )

Will adding a check for the kernel (NT in this case) using os.name after the above snippet and then using an if statement to trigger a logger.warning warning the user in case the error (error message) is above a certain length do the job?

@MohsenAAkeel
Copy link

I was taking a look at this as well (saw first issue tag). I think sys.platform would be a better method of checking what OS the user is running as os.name is good for checking posix compliance.

@uranusjr
Copy link
Member

uranusjr commented Jun 8, 2021

@MohsenAAkeel Use this instead

from pip._internal.utils.compat import WINDOWS

@pradyunsg
Copy link
Member

Resolved by #10046.

FYI @OBITORASU -- GitHub need "Fixes ..." to trigger autoclosing, so "Fixes Issue ..." didn't work. :)

@OBITORASU
Copy link
Contributor

Resolved by #10046.

FYI @OBITORASU -- GitHub need "Fixes ..." to trigger autoclosing, so "Fixes Issue ..." didn't work. :)

I will keep that in mind from next time on, thanks for the heads up! ^-^

inmantaci added a commit to inmanta/inmanta-core that referenced this issue Jul 26, 2021
Bumps [pip](https://github.com/pypa/pip) from 21.1.3 to 21.2.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p>
<blockquote>
<h1>21.2.1 (2021-07-25)</h1>
<h2>Process</h2>
<ul>
<li>The source distribution re-installation feature removal has been delayed to 21.3.</li>
</ul>
<h1>21.2 (2021-07-24)</h1>
<h2>Process</h2>
<ul>
<li><code>pip freeze</code>, <code>pip list</code>, and <code>pip show</code> no longer normalize underscore
(<code>_</code>) in distribution names to dash (<code>-</code>). This is a side effect of the
migration to <code>importlib.metadata</code>, since the underscore-dash normalization
behavior is non-standard and specific to setuptools. This should not affect
other parts of pip (for example, when feeding the <code>pip freeze</code> result back
into <code>pip install</code>) since pip internally performs standard PEP 503
normalization independently to setuptools.</li>
</ul>
<h2>Deprecations and Removals</h2>
<ul>
<li>Git version parsing is now done with regular expression to prepare for the
pending upstream removal of non-PEP-440 version parsing logic. (<code>[#10117](pypa/pip#10117) &lt;https://github.com/pypa/pip/issues/10117&gt;</code>_)</li>
<li>Re-enable the &quot;Value for ... does not match&quot; location warnings to field a new
round of feedback for the <code>distutils</code>-<code>sysconfig</code> transition. (<code>[#10151](pypa/pip#10151) &lt;https://github.com/pypa/pip/issues/10151&gt;</code>_)</li>
<li>Remove deprecated <code>--find-links</code> option in <code>pip freeze</code> (<code>[#9069](pypa/pip#9069) &lt;https://github.com/pypa/pip/issues/9069&gt;</code>_)</li>
</ul>
<h2>Features</h2>
<ul>
<li>
<p>New resolver: Loosen URL comparison logic when checking for direct URL reference
equivalency. The logic includes the following notable characteristics:</p>
<ul>
<li>The authentication part of the URL is explicitly ignored.</li>
<li>Most of the fragment part, including <code>egg=</code>, is explicitly ignored. Only
<code>subdirectory=</code> and hash values (e.g. <code>sha256=</code>) are kept.</li>
<li>The query part of the URL is parsed to allow ordering differences. (<code>[#10002](pypa/pip#10002) &lt;https://github.com/pypa/pip/issues/10002&gt;</code>_)</li>
</ul>
</li>
<li>
<p>Support TOML v1.0.0 syntax in <code>pyproject.toml</code>. (<code>[#10034](pypa/pip#10034) &lt;https://github.com/pypa/pip/issues/10034&gt;</code>_)</p>
</li>
<li>
<p>Added a warning message for errors caused due to Long Paths being disabled on Windows. (<code>[#10045](pypa/pip#10045) &lt;https://github.com/pypa/pip/issues/10045&gt;</code>_)</p>
</li>
<li>
<p>Change the encoding of log file from default text encoding to UTF-8. (<code>[#10071](pypa/pip#10071) &lt;https://github.com/pypa/pip/issues/10071&gt;</code>_)</p>
</li>
<li>
<p>Log the resolved commit SHA when installing a package from a Git repository. (<code>[#10149](pypa/pip#10149) &lt;https://github.com/pypa/pip/issues/10149&gt;</code>_)</p>
</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/bd41229cdced10d2b7c304a1ef2d61baad3c7da0"><code>bd41229</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/765a4b40227653d22d30c85448ec343e542f41d7"><code>765a4b4</code></a> Bump for development</li>
<li><a href="https://github.com/pypa/pip/commit/3d25c5327d0887271958999ac44709728b5c4f5a"><code>3d25c53</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/27b9a9c35c96e4032af7603ca03651d8f5917681"><code>27b9a9c</code></a> Update AUTHORS.txt</li>
<li><a href="https://github.com/pypa/pip/commit/b9dbab277b7206fd9efc16cef793ab01ccfb32fb"><code>b9dbab2</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10199">#10199</a> from uranusjr/remove-local-sdist-reinstall</li>
<li><a href="https://github.com/pypa/pip/commit/33b7f0cd9e0fff6bd532941a530d7f8b3472eb55"><code>33b7f0c</code></a> Remove deprecated sdist reinstall feature for 21.2</li>
<li><a href="https://github.com/pypa/pip/commit/a8b8d4d7fe214a0d4e78b0d98d0b97e471858fe5"><code>a8b8d4d</code></a> Document how to install provides_extras from local wheel file (<a href="https://github-redirect.dependabot.com/pypa/pip/issues/9698">#9698</a>)</li>
<li><a href="https://github.com/pypa/pip/commit/239a30737277887fed9f609ae786a0fb80591be4"><code>239a307</code></a> Error handling upon <code>uninstall</code> invalid parameter (<a href="https://github-redirect.dependabot.com/pypa/pip/issues/10171">#10171</a>)</li>
<li><a href="https://github.com/pypa/pip/commit/5e86264b5ac1c62d08f91a16a068647d8872e4e8"><code>5e86264</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10189">#10189</a> from harupy/type-annotations-index-models</li>
<li><a href="https://github.com/pypa/pip/commit/02b1855b45eb143b524f773eafb46d77406504d3"><code>02b1855</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/pypa/pip/issues/10188">#10188</a> from harupy/type-annotations-req</li>
<li>Additional commits viewable in <a href="https://github.com/pypa/pip/compare/21.1.3...21.2.1">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=21.1.3&new-version=21.2.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C: error messages Improving error messages good first issue A good item for first time contributors to work on type: feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

5 participants