LoginSignup
15
4

More than 1 year has passed since last update.

Poetryでwhl does not existとなる問題への対処

Last updated at Posted at 2021-09-23

環境

Windows 10 Pro
Python 3.9.7
Poetry 1.1.10

問題点

poetryを導入後、poetry installpoetry addpoetry self updateなどを行おうとすると

Package operations: 10 installs, 0 updates, 0 removals
  • Installing pyparsing (2.4.7)
  ValueError
  File \C:\Users\usr\AppData\Local\pypoetry\Cache\artifacts\92\0f\cf\(略)\pyparsing-2.4.7-py2.py3-none-any.whl does not exist

  at ~\.poetry\lib\poetry\_vendor\py3.9\poetry\core\packages\file_dependency.py:40 in __init__
       36│             except FileNotFoundError:
       37│                 raise ValueError("Directory {} does not exist".format(self._path))
       38│
       39│         if not self._full_path.exists():
    →  40│             raise ValueError("File {} does not exist".format(self._path))
       41│
       42│         if self._full_path.is_dir():
       43│             raise ValueError("{} is a directory, expected a file".format(self._path))
       44│

とエラーとなります。

原因

Poetryのissue4479に同様の問題が上がっていました。
パスの表記方法がWindowsを考慮せず、先頭にバックスラッシュ(\)が入ってしまうのが原因とのこと。
確かにエラーメッセージでも\C:\Users\usr\AppData~とCの前にバックスラッシュが入ってしまっています。

解決策

Pull Requestがされているようなので、そのうち修正されるのではないかと思います。
すぐに解決したい場合は、以下の手順でPull Requestと同じようにコードを修正することで直りました。

  • poetryがインストールされているフォルダ(デフォルトだとC:¥Users¥ユーザー名¥.poetry)のpoetry/installation/executor.py(C:¥Users¥ユーザー名¥.poetry¥lib¥poetry¥installation¥executor.py)をテキストエディターで編集
  • [追記]自分の環境では上記にexecutor.pyがありましたが、C:\Users\<username>\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\installation\にある場合もあるようです。

  • importの14行目にfrom poetry.core.packages.utils.utils import url_to_pathを追加

executor.py(変更前)
 from poetry.core.packages.file_dependency import FileDependency
 from poetry.core.packages.utils.link import Link
 from poetry.core.pyproject.toml import PyProjectTOML

executor.py(変更後)
 from poetry.core.packages.file_dependency import FileDependency
 from poetry.core.packages.utils.link import Link
 from poetry.core.packages.utils.utils import url_to_path # <- 追加(14行目)
 from poetry.core.pyproject.toml import PyProjectTOML
  • 620行目(上を既に追加してる場合621行目)のPath(archive.path)を削除するかコメントアウトし、url_to_path(archive.url)へ変更
executor.py(変更前)
FileDependency(
    package.name,
    Path(archive.path)
    if isinstance(archive, Link)
    else archive,
).hash(hash_type),

executor.py(変更後)
FileDependency(
    package.name,
    # Path(archive.path) # <- 削除するかコメントアウト(620or621行目)
    url_to_path(archive.url) # <- 追加
    if isinstance(archive, Link)
    else archive,
).hash(hash_type),
15
4
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
4