以前に Python で Google API Key を使わずに Google 翻訳を利用する というメモを書きました。 しかし、現時点で googletrans の安定版である 3.0.0 では AttributeError: 'NoneType' object has no attribute 'group'
エラーになってしまいます。 これは Google 側の仕様変更に起因するエラーのようです。 この問題は error in result (AttributeError: 'NoneType' object has no attribute 'group') #234 で言及されており、googletrans のプレリリース版では一応、動作するようです。
現時点のリリース
現時点で googletrans の Release history は以下のようになっていました。
Version | Date | Status |
---|---|---|
4.0.0rc1 | 2020/12/9 | PRE-RELEASE |
3.1.0a0 | 2020/12/2 | PRE-RELEASE |
3.0.0 | 2020/6/14 | STABLE |
既存ライブラリのアンインストール
既に 3.0.0 などをインストールしている場合は事前にアンインストールしておきます。
pip uninstall googletrans
PRE-RELEASE 版のインストール
4.0.0-rc1 または 3.1.0a0 でこの問題は (今の所) 修正されているようです。 4.0.0-rc1 をインストールする場合は以下を実行します。
pip install googletrans==4.0.0-rc1
3.1.0a0 をインストールする場合は以下を実行します。
pip install googletrans==3.1.0a0
サンプルスクリプト
以前にメモしたサンプルスクリプト と同じ内容で動作しました。
#!/usr/bin/env python3
from googletrans import Translator
translator = Translator()
message = translator.translate('This is a pen.', src='en', dest='ja')
print(message.text)
コメント