LoginSignup
12
6

More than 5 years have passed since last update.

Debian8 に python3-pip をインストールしたら pip3 が "ImportError: No module named 'packaging' で動かなかった時の防備録(解決)

Last updated at Posted at 2017-02-07

はじめに

これは 2017/2/7 に踏んでしまった python3-pip の地雷に関する単なる防備録です。現状は未解決です。解決方法がわかり次第、記事を更新する予定です どうやら解決したっぽいです。

なお、私は python 歴わずか数日、 python に関してはほとんど素人です。間違ったことしていればコメントください。

もともと、次のシステムに Jupyter をインストールしてみようとしたのが発端。

補足しておくと、この時点では次のように python2.7 系は pip も含めて動作していました。

python3 をインストールしてみたが...

とりあえず python3 をインストールしてみる。

shell$ sudo apt-get install python3
shell$ sudo apt-get install python3-dev
shell$ sudo apt-get install python3-pip

ところが、何故か、pip3 を動かそうとすると失敗する

shell$ sudo pip3 install jupyter
Traceback (most recent call last):
  File "/usr/bin/pip3", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named 'packaging'

パッケージをアップグレードしてみたが

ここで痛恨のミス。パッケージのバージョン/リビジョンが古いのかと思って、パッケージをアップグレードしてしまう。

shell# apt-get update
shell# apt-get upgrade

失敗したなと後悔したのは次の2点

  1. 前節の python3 インストールした時のログを消してしまった。
  2. 今まで正常に動いていた python2 もアップグレードしてしまった。

その結果、

shell$ sudo pip3 install jupyter
Traceback (most recent call last):
  File "/usr/bin/pip3", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named 'packaging'

pip3 だけでなく、

shell$ pip --version
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named 'packaging'

pip まで動かなくなってしまった。

解決策をネットで探す

ここに至って、やっとネットで解決策を探すことに。。。その結果、次のページがひっかかる。

かなり最近のことらしい(2017/2/7 から4日前くらい)。

で、ここの記事とおり、やってみる。

shell# apt-get purge -y python-pip
shell# wget https://bootstrap.pypa.io/get-pip.py
shell# python ./get-pip.py
shell# apt-get install python-pip

その結果 pip の方は復活。

shell# pip --version
pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)

しかし、pip3 の方は相変わらずダメ。

shell# pip3 --version
Traceback (most recent call last):
  File "/usr/bin/pip3", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named 'packaging'

どうしたものか。。。 (続く)

twitter で助言をいただいて pip3 が動くようになる

で、試してみました。

shell# apt-get purge python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libblas-common libblas3 libgfortran3 liblapack3 python3-chardet
  python3-colorama python3-distlib python3-html5lib python3-pkg-resources
  python3-requests python3-setuptools python3-six python3-urllib3
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  python3-pip*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 452 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 39218 files and directories currently installed.)
Removing python3-pip (1.5.6-5) ...
Processing triggers for man-db (2.7.0.2-5) ...
shell# python3 get-pip.py
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Requirement already up-to-date: setuptools in /usr/local/lib/python3.4/dist-packages
Collecting wheel
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Collecting six>=1.6.0 (from setuptools)
  Using cached six-1.10.0-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools)
  Using cached appdirs-1.4.0-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools)
  Using cached packaging-16.8-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools)
  Using cached pyparsing-2.1.10-py2.py3-none-any.whl
Installing collected packages: pip, wheel, six, appdirs, pyparsing, packaging
  Found existing installation: six 1.8.0
    Uninstalling six-1.8.0:
      Successfully uninstalled six-1.8.0
Successfully installed appdirs-1.4.0 packaging-16.8 pip-9.0.1 pyparsing-2.1.10 six-1.10.0 wheel-0.29.0
shell# apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libblas-common libblas3 libgfortran3 liblapack3
Use 'apt-get autoremove' to remove them.
Recommended packages:
  python3-wheel
The following NEW packages will be installed:
  python3-pip
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/97.2 kB of archives.
After this operation, 452 kB of additional disk space will be used.
Selecting previously unselected package python3-pip.
(Reading database ... 39166 files and directories currently installed.)
Preparing to unpack .../python3-pip_1.5.6-5_all.deb ...
Unpacking python3-pip (1.5.6-5) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up python3-pip (1.5.6-5) ...
shell# pip3 --version
pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

動いた!

12
6
2

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
12
6