0
0

Dockerを用いたPython環境をクラウドに移行した際のNo module named 'fugashi.fugashi'

Posted at

解決に結構沼ったので書き残しておきます。

問題

Docker imageを持ち込んでクラウドで動作させる際に、Docker内のpython環境でfugashiがインストールされているにもかかわらず以下のようなエラーが発生するようになった。

Traceback (most recent call last):
  File "/home/users/xxxx/.py", line 1, in <module>
    from fugashi import Tagger
  File "/home/users/xxxx/.local/lib/python3.11/site-packages/fugashi/__init__.py", line 1, in <module>
    from .fugashi import *
ModuleNotFoundError: No module named 'fugashi.fugashi

解決法

Docker内のPython環境で--no-warn-script-locationと--force-reinstallオプションを付けてpip installする。

私の場合はローカルで動作させる必要があったので
https://pypi.org/project/fugashi/
上記のサイトよりバージョンに合ったfugashiのwhlファイルをダウンロードして以下のように実行した。

pip install ./*.whl --no-warn-script-location --force-reinstall --no-index --find-links=./*.whl

経緯

Docker imageをクラウドに持ち込んでdocker load -iしていたが、何らかの原因でfugashiのみPATHが通らなくなっていた。

whlからfugashiをreinstallすると

WARNING: The scripts fugashi, fugashi-build-dict and fugashi-info are installed in '/home/users/xxx/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

上記の警告が出されて--no-warn-script-locationオプションを付けることで解決に至った。

ローカルでDocker imageからコンテナを起動させた際には問題なくfugashiが動作していたため、詳しい原因はわからないが、クラウド側のdockerがオプション等を勝手に付けられるといった制限の付いたものだったので、そこが原因だと思われる。

0
0
0

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
0
0