0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google Cloud functionsでNatural Language APIを使おうとして躓いた話

Last updated at Posted at 2021-04-01

1.はじめに

最近Cloud Functionsとfirebaseの組み合わせでアプリを作っている。
すごく便利なので色々処理を後ろに投げている(主にpythonでの処理)。

その中で、ニュース記事からentitiyを抽出しよう、ということに↓
フロント側でワードを指定すると、後ろのCloud Function側にリクエストを送り、
・ニュース記事検索(GoogleNews)
・Cloud Function側でNatural Language APIでentity抽出
結果をエクセルとかで返す。

早速、一個Cloud Functionsを作って
requirements.txtに

# Function dependencies, for example:
# package>=version
pandas==1.2.3
~なんやかんや
google-cloud==0.34.0
google-cloud-language==2.0.0

などと指定してdeploy。

2.問題発生

すると失敗してしまう。
エラー:

Traceback (most recent call last):
File "***.py", line *, in <module>
from google.cloud.language import enums
ImportError: cannot import name enums

main.py側では

import google.cloud
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types

で使っていた。enumsがないとのこと。

3.解決

色々情報を探って紆余曲折の結果、
同じコードできちんと動いてたgoogle colabで!pip freezeで
情報を見ると、google-cloud-language==1.2.0が入っていたので、
requirements.txtに

google-cloud-language==1.2.0

と2.0.0じゃなくて1.2.0を指定すれば入れば動いた(deployに成功)。

pypiから
google-cloud-language==1.2.0
は発見できなかったので
google-cloud-language==2.0.0
とか
gapic-google-cloud-language-v1beta2 0.15.3
とか関連ありそうなのを試したがうまくいかなかった。
pypiを見てもそのバージョンが見当たらないので非推奨かもしれない。
根本原因はNatural Language APIの変更履歴などを追わないといけないけれど、
ほぼ英語情報しかなくて苦労している最中。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?