Python pip3 – pip upgradeした後 「cannot import name ‘main’ 」error

はてなブックマーク - Python pip3 – pip upgradeした後 「cannot import name ‘main’ 」error
LINEで送る
Pocket

目次

現象

pip3を実行するときに

pip3バージョンが古いから、最新版にupgradeしてください。

というメッセージが出て、「指示」通りに下のコマンドを実行しましたら

pip3 install --upgrade pip

こんなエラーが出てきました!

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'

これは、実は、そのまま実行してはいけませんでした。

復旧

復旧するには

一旦下のコマンドを実行して、戻しましょう。

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

原因

今回この事象が発生したOSはubuntuですので(debian系全部言えるかもしれませんが)pip3は

osのパッケージをメンテしている人が提供しているもので

https://packages.ubuntu.com/ja/trusty/python3-pip

pipパッケージのものではありません。

https://pip.pypa.io/en/stable/

なので、pipにアップグレードすると、不整合が発生します。

どうすれば良いか

アップグレードしないまま使う

アップグレードしないと作業できないなどの理由がなければ、そのままpipのバージョンが低いままでも問題はないはずです。(私の場合は8.1.1です。)

virtualenvを使います。

下の記事④のところに、virtualenvの設定について説明があります。ご参照ください。

RaspberryPiで顔認識OpenCVで

ご参考になれば幸いです。

はてなブックマーク - Python pip3 – pip upgradeした後 「cannot import name ‘main’ 」error
LINEで送る
Pocket

4 Comments

Add a Comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close