pip: ImportError: cannot import name 'sysconfig' (Ubuntu 16.04)
- Pip version:
- Python version: 3.6.5
- Operating system: Ubuntu 16.04.4 LTS
Description:
Similar problem to #5356 but with a different version of Ubuntu. The solution proposed in #5356 doesn’t solve the problem with this version of Ubuntu
After installing Python 3.6 from jonathonf repository in a clean version of Ubuntu, I’ve found the following error while trying to install Pip
Note that trying to install Pip with the Python version that comes by default (3.5.2 ) doesn’t give any problem.
What I’ve run:
python3.6 get-pip.py
The error message:
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/tmpodo51doi/pip.zip/pip/_internal/__init__.py", line 42, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/index.py", line 25, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/download.py", line 35, in <module>
File "/tmp/tmpodo51doi/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/tmpodo51doi/pip.zip/pip/_internal/__init__.py", line 42, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/index.py", line 25, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/download.py", line 35, in <module>
File "/tmp/tmpodo51doi/pip.zip/pip/_internal/locations.py", line 10, in <module>
ImportError: cannot import name 'sysconfig'
Workaround I have found
- Download Python source from https://www.python.org/
- Decompress the source code
- Install the following dependencies:
sudo apt-get install zlib1g-dev
(needed to compile Python)sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
(needed by Pip to make SSL requests) - Compile and install Python:
./configure
make
make install
- Python 3.6 with Pip should be installed.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 12
- Comments: 16
Commits related to this issue
- install python3-distutils Fixes pypa/pip#5367 — committed to golemfactory/ansible-role-golem-source by etam 6 years ago
- install python3-distutils workaround pypa/pip#5367 — committed to golemfactory/ansible-role-golem-source by etam 6 years ago
I also saw a similar error.
However, by installing
python3-distutils
it was possible to avoid this error.sudo apt-get install python3-distutils
I had a similar problem on Ubuntu 16.04 (specifically “from distutils import dist, sysconfig ImportError: cannot import name ‘dist’”) and “sudo apt-get install python3-distutils” solved it. Thank you!
Tried installing Python 3.6 from
ppa:deadsnakes/ppa
instead of fromppa:jonathonf/python-3.6
and it’s installing Pip correctly. It looks like the version of jonathonf it’s broken in some way.Edit: Just noticed that some comments in the Stack Overflow answer adress this problem with the jonathonf repository
I can confirm that removing
ppa:jonathonf/python-3.6
and then addingppa:deadsnakes/ppa
and reinstallingpython3.6
fixes this problem on Linux Mint 18.3.Info on removing current PPA: https://askubuntu.com/a/173209/823909 Adding new Python3.6 PPA: https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get
@wakiyamap Thanks, your solution
apt install python3-distutils
worked for me also.I have just upgraded to Python 3.6.5 on Ubuntu 16.04.4 and imports for matplotlib and calls to pip all failed with the same error.
This fix needs to be widely disseminated.
@RandyRomero @wakiyamap thanks,
apt install python3-distutils
works for me too.@jonbesga I’m on 16.04.4 LTS and it worked. EDIT - I’m using vagrant, did “vagrant box update” a moment ago, I’m on 20180504)
Generally, not a pip-related issue if you ask me, it has more to do with Ubuntu packaging
@jonbesga Thanks for the workaround, also experiencing this issue with the exact same versions of python 3.6 and ubuntu…