2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntu16.0.4 LTS でpython3.6をインストールしたときにpip3が更新されない場合の対処法

Last updated at Posted at 2018-07-03

エラーの出力

https://www.python.jp/install/ubuntu/index.html
上の手順に則ってubuntuにpython3.6をインストールした際に最後のコマンドである

sudo python3.6 get-pip.py

を実行した際にエラーが発生する場合がある。

その際は以下のようなエラーが出力される。
※下記の例はrootで実行しています。

root@test:~# python3.6 get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 20649, in <module>
    main()
  File "get-pip.py", line 197, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/download.py", line 35, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/locations.py", line 10, in <module>
ImportError: cannot import name 'sysconfig'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "get-pip.py", line 20649, in <module>
    main()
  File "get-pip.py", line 197, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/download.py", line 35, in <module>
  File "/tmp/tmpruuzep87/pip.zip/pip/_internal/locations.py", line 10, in <module>
ImportError: cannot import name 'sysconfig'

解決策

これは単にpython3-distutilsのインストールが不足している場合に発生する問題の様です。前述のエラーが出た場合、以下の順にコマンドを実行すると解決すると思います。

sudo apt install python3-distutils
sudo python3.6 get-pip.py

参考リンク

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?