eco0o0o0のブログ

たまにプログラミングしてる。検索してもでてこないことをたまに記事にします。

herokuでgoogletransをインストールした。

googletransというのは、pythonのライブラリで要するにgoogle翻訳のことです。

早速heroku上で使おうとアプリのrequirements.txtに googletrans==2.3.0と書き加え、コミットしたのですが、いざコードを実行すると、

AttributeError: 'NoneType' object has no attribute 'group'

となぜかエラーが出ました。 調べてみると全世界中のgoogletrans使用者が同じエラーがでるようです。 そこで非公式らしいですが、以下のgitを代わりに使うことでエラーを免れることができます。 github.com

gitをrequirements.txtでインストールする方法はterminalでやるように

git+https://github.com/BoseCorp/py-googletrans

としてやれば勝手に入れてくれます。

-----> Installing requirements with pip Collecting git+https://github.com/BoseCorp/py-googletrans (from -r /tmp/build_f77fe88c66166867dc0d39a53ac7b93f/requirements.txt (line 12)) Cloning https://github.com/BoseCorp/py-googletrans to /tmp/pip-ywjbgq7i-build Installing collected packages: googletrans Running setup.py install for googletrans: started Running setup.py install for googletrans: finished with status 'done' Successfully installed googletrans-2.3.0

インストール完了です。 これで、heroku上のpythonで文字列を問題なく翻訳できるようになりました。