LoginSignup
11
10

More than 5 years have passed since last update.

requirements.txtは#でコメントアウトできる

Last updated at Posted at 2017-09-01

AWSでElastic Beanstalk上で動作するWEB APIを開発する際、微妙にバージョンが古いPython3.4を利用する必要があります

そして今回、Python3.6ではきちんと動作するのに、3.4では細かくバージョン指定しなければ動作しないライブラリが存在するという事態に当たってしまいました。

そのため、requirements.txtに「なぜ最新のバージョンを使っていないのか」という情報をメモするためコメントアウトする方法を調べたところ、Python本体と同様#でOKでした。

...
ply==3.8
# Python3.4では最新バージョンのインポートに失敗するため
protobuf==3.2.0rc2                                               
pyasn1==0.3.3
...

こちらの記載で見つけました。普段はpip freeze > requirements.txtで自動生成するのでコメント書く機会はそれほど無さそうですけど。

A line beginning with # is treated as a comment and ignored, so you can just place your comment on the line above instead of on the same line.

これで今回の記事の主題は終わりなのですが、「3.4では細かくバージョン指定しなければ動作しない」という挙動自体は納得できないので、ひとまず動作できる状態になったら調べてみようと思います。

具体的には、Python3.4でprotobufライブラリの3.4.0のインポートにエラーが出てしまうため、3.2.0rc2を利用する必要がありました(その前後のバージョンでもダメでした)。

  File "/home/ninomiyt/eb-virt/local/lib/python3.4/site-packages/google/cloud/client.py", line 26, in <module>
    from google.cloud._helpers import _determine_default_project
  File "/home/ninomiyt/eb-virt/local/lib/python3.4/site-packages/google/cloud/_helpers.py", line 33, in <module>
    from google.protobuf import duration_pb2
ImportError: No module named 'google.protobuf'

本来ならエラーの原因を特定してプルリク送る(もしくはissueをあげる)後に記事にできるとかっこいいんでしょうけど、リリースして仕事を終わらせるほうをひとまずは優先します。

11
10
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
11
10