python-poetry/poetry

Poetry on Windows fails with File does not exists error

lululukas opened this issue · 14 comments

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • OS version and name: Windows 10
  • Poetry version: 1.2.0a2
  • Link of a Gist with the contents of your pyproject.toml file: Will publish if necessary for this issue, don't think it is.

Issue

When trying to poetry add a dependency or do poetry install or poetry update, the command fails with an error saying that the file does not exist. The file refers to the weel of any dependencies that need to be installed. However, the file actually does exist at the correct location, but is somehow not found by poetry. I think this is due to a leading \ in the path. I haven't looked at the code, but I use bash bundled with git-for-windows in Windows Terminal. I assume that has something to do with the problem.

This is the error message, you can see the leading backslash in the path which I think is the culprit:

  ValueError

  File \C:\Users\<user>\AppData\Local\pypoetry\Cache\artifacts\ac\59\ac\9fc6b3c55594c6a7395665b20538ee05fb2ade328e723d2761b44c70ca\typed_ast-1.4.3-cp37-cp37m-win_amd64.whl does not exist

  at c:\users\<user>\appdata\roaming\pypoetry\venv\lib\site-packages\poetry\core\packages\file_dependency.py:41 in __init__
       37│             except FileNotFoundError:
       38│                 raise ValueError("Directory {} does not exist".format(self._path))
       39│
       40│         if not self._full_path.exists():
    →  41│             raise ValueError("File {} does not exist".format(self._path))
       42│
       43│         if self._full_path.is_dir():
       44│             raise ValueError("{} is a directory, expected a file".format(self._path))
       45│

However, the file does exist:

❯ file "C:\Users\<user>\AppData\Local\pypoetry\Cache\artifacts\ac\59\ac\9fc6b3c55594c6a7395665b20538ee05fb2ade328e723d2761b44c70ca\typed_ast-1.4.3-cp37-cp37m-win_amd64.whl"
C:\Users\<user>\AppData\Local\pypoetry\Cache\artifacts\ac\59\ac\9fc6b3c55594c6a7395665b20538ee05fb2ade328e723d2761b44c70ca\typed_ast-1.4.3-cp37-cp37m-win_amd64.whl: Zip archive data, at least v2.0 to extract, compression method=deflate

Edit:

I get the same error using powershell, so it seems like the issue is not related to using bash.

As of today I have the exact same problem. (Havent updated any package in a while, so might have been there earlier).

So far I've tried:

  • updating poetry
  • clearing the poetry cache
  • removing all virtual envs
  • reinstalling all packages
  • reinstalling poetry

I am on the latest version of poetry.

The cause of the issue is in executor.py and core/packages/utils/link.py.

Links (file:///C:/Users...) are converted into absolute paths (/C:/Users...) without accounting for Windows.

This issue only surfaces when using the cached local packages.

I am experiencing this exact issue on Poetry 1.1.10. I am using pyenv to manage my python versions, currently using the most recent available, 3.9.7. Not sure how to proceed other than to use pip for now and remake dependencies once this has been solved. Thank you for your PR! Hopefully it will be done shortly.

For anyone who ran into this and bricked their installation, here's how to fix it:

  1. downgrade poetry to 1.1.9
  2. delete the cache folder MANUALLY (using poetry cache clear did not work, the leading \ still appeared afterwards.)

You can locate your cache folder by calling poetry config --list.

Unfortunately the fix was temporary on my end. Still running into this regularly and have to wipe the cache each time.

@jonapich try applying my patches at #4549

For me this problem happens, when i tried to install package that was already installed and placed in Cache folder (for example, install dependencies for another project).

Manually deleting folder Cache solves the problem on poetry version 1.11, but issue should be fixed in next version.

dibog commented

When will there be a fix for this?

@dibog Wait a while for the next release. In the meantime, you can install the branch with:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python - --git https://github.com/python-poetry/poetry.git@1.1

@dibog Wait a while for the next release. In the meantime, you can install the branch with:

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python - --git git+https://github.com/python-poetry/poetry.git@1.1

Is this also available in the preview version (1.2.x) yet? I want to keep using that version, but I really need this patch.

@lululukas You can adjust the command accordingly, replace 1.1 with master

Failed with ERROR: Invalid requirement: 'git+git+https://github.com/python-poetry/poetry.git@master'.

You have to remove the git+ so (Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python - --git https://github.com/python-poetry/poetry.git@master works.

Thanks for the patch!

I experienced something similar on Windows 11 trying to install Sphinx. The problem was fixed by enabling long path lengths.

My error

ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\<me>\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\LocalCache\\Local\\pypoetry\\Cache\\virtualenvs\\repo-zAvtZT_G-py3.11\\Lib\\site-packages\\sphinxcontrib\\serializinghtml\\locales\\ar\\LC_MESSAGES\\sphinxcontrib.serializinghtml.mo'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths

https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=powershell#enable-long-paths-in-windows-10-version-1607-and-later

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.