Closed paulhindemith closed 1 year ago
ご利用ありがとうございます。すみませんが、このようなエラーは見たことがありません……
-u
の引数だけを使うと動作しますか?ご返信いただきありがとうございますmm
頂いたご質問に一つ一つお答えしますと
ファイルを読む権限はありますか?
はい、問題のコードの直前に、os.access("/mnt/integration_test/outputs/custom.dic", os.R_OK)
と権限の確認コードを仕込みましたが、True でした。
CLIからMeCabに同じ引数を渡すとうまく動作しますか?
動作しませんでした。同じく no such file or directory
のエラーになりました。mecab-python3 ではなく、mecab の動作が意図しないものになるみたいですね...
-u の引数だけを使うと動作しますか?
CLIからMeCabに -u の引数のみ指定しましたが、 no such file or directory
のエラーになりました。
上記のエラーは Cloud Run でのみ発生しており、Windows のローカルで実行した docker 環境ではエラーにならないのです...
何かアーキテクチャの違いがでるのでしょうか...
引数の文字列を作成するコードは共有できますか?もしかして括弧が問題になっているかもしれません。
アプリのコードは以下で、
self.mecab = MeCab.Tagger(f'-d "{DIC_DIR_PATH}" -u "{userdic}" -F "{FORMAT}"')
デバッグのために書いた以下もあります。
res = subprocess.run(
f'echo "あ" | mecab -u "/mnt/integration_test/outputs/custom.dic"',
shell=True,
capture_output=True)
ctx.logger.info(f"stdout: {res.stdout.decode('utf-8')}")
どちらもエラーになりました。
Windows からではなく、Mac(M1、M2 でない)のローカル環境からもMeCab コマンドを試しましたが、上記のエラーは再現できませんでした。 Google Cloud の Cloud run と MeCab との相性が悪いような気がします。
こちら解決いたしましたmm
/mnt を WORKDIR として設定している /app に設定することで無事参照可能になりました。 Python からは参照できていたので非常にわかりにくかったのですが、どうも /mnt 以下はなにがしかの制御が行われているみたいです。
もうやめてしまおうかと思っていたのですが、ご相談乗っていただき希望が湧きました。
どうもありがとうございましたmm
ご報告ありがとうございます、解決できてなによりです!
現在の状況
mecab-python3 を利用して MeCab で形態素解析を行うアプリケーションを開発しています。 mecab のオプション -u を利用して
/mnt/integration_test/outputs/custom.dic
に存在するユーザー辞書を利用した形態素解析を行いたいです。 上記のパスにはファイルが確かに存在し、直前にos.path.exists('/mnt/integration_test/outputs/custom.dic')
としてもTrue
となるので間違いなくファイルは存在するのですが、下記の通りno such file or directory: /mnt/integration_test/outputs/custom.dic
のエラーが出てしまいます。エラーが起きている環境は、python:3.11.1-bullseye イメージを利用したコンテナ内で起きています。 この現象はローカルの Windows Docker 環境では再現できないのですが、Google Cloud の Cloud Run を利用した場合に起きております。
なぜこのようなエラーになってしまうのか考えうる原因について、お力を貸していただけませんでしょうか。
Error Message