Let's Encryptでpipのエラーが出た際に試す価値のある方法


Let's Encrypt という証明書サービスの存在を知ったので、さっそくうちのサイトに導入してみようかと意気込んでみたわけですが、証明書の取得中になぜかこんなエラーが出てしまいまして。

参考: 無料でHTTPS化できる「Let's Encrypt」をやってみた ※install.sh付き

Installing Python packages...
/opt/eff.org/certbot/venv/bin/python: No module named pip.__main__; 'pip' is a package and cannot be directly executed
Traceback (most recent call last):
  File "/tmp/tmp.npkn4VEZsM/pipstrap.py", line 177, in <module>
    sys.exit(main())
  File "/tmp/tmp.npkn4VEZsM/pipstrap.py", line 149, in main
    pip_version = StrictVersion(check_output([python, '-m', 'pip', '--version'])
  File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['/opt/eff.org/certbot/venv/bin/python', '-m', 'pip', '--version']' returned non-zero exit status 1

はて、これは何じゃラホイと怪訝に思って調べてみると、どうやら最新版の cert-bot では問題があるらしく、基本的にはバージョンは 0.31.0 に固定にしたほうがいいでやんすということで。

早速解決法を調べてみると、Let's Encryptのコミュニティでそのものズバリな解法をしている方がいらっしゃいました。

Certbot auto started failing with ’ No module named pip.main

ericb2038さんの回答を適時置き換えたコードがこちら

rm /usr/bin/certbot-auto*
wget https://raw.githubusercontent.com/certbot/certbot/75499277be6699fd5a9b884837546391950a3ec9/certbot-auto
mv certbot-auto /usr/bin/
chmod +x /usr/bin/certbot-auto
certbot-auto certonly --webroot -w /var/www/hoge -d hoge.com --email [email protected] --no-self-upgrade

オプションの --no-self-upgrade がキモですね!

試してみたところ、無事に先へ進めるメッセージが出ました。

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/hoge.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/hoge.com/privkey.pem
   Your cert will expire on 2019-12-06. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

というわけで、皆さん気軽にSSLライフをエンジョイしましょー!