EC2のubuntu16.04にPython 3.6をインストールしたらImportErrorが出た

結論

python3-distutilsを入れる

sudo apt install python3-distutils

参考:
https://github.com/pypa/pip/issues/5356

背景

EC2のubuntu16.04にpython Japan様のガイドに従ってPython3.6のインストールを試みたところ、get-pip.pyの実行時にエラーが出た。

$ sudo 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/tmpcvlsw3a6/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/download.py", line 35, in <module>
  File "/tmp/tmpcvlsw3a6/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/tmpcvlsw3a6/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/index.py", line 25, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/download.py", line 35, in <module>
  File "/tmp/tmpcvlsw3a6/pip.zip/pip/_internal/locations.py", line 10, in <module>
ImportError: cannot import name 'sysconfig'
$
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.