Pip: ImportError: Name „sysconfig“ kann nicht importiert werden (Ubuntu 16.04)

Erstellt am 3. Mai 2018  ·  16Kommentare  ·  Quelle: pypa/pip

  • Pip-Version:
  • Python-Version: 3.6.5
  • Betriebssystem: Ubuntu 16.04.4 LTS

Beschreibung:

Ähnliches Problem wie #5356, aber mit einer anderen Version von Ubuntu. Die in #5356 vorgeschlagene Lösung löst das Problem mit dieser Version von Ubuntu nicht

Nach der Installation von Python 3.6 aus dem Jonathonf- Repository in einer sauberen Version von Ubuntu habe ich beim Versuch, Pip zu installieren, den folgenden Fehler gefunden

Beachten Sie, dass der Versuch, Pip mit der standardmäßig mitgelieferten Python-Version (3.5.2 ) zu installieren, kein Problem darstellt.

Was ich gelaufen bin:

python3.6 get-pip.py

Die Fehlermeldung:

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'

Abhilfe habe ich gefunden

  • Laden Sie den Python-Quellcode von https://www.python.org/ herunter.
  • Dekomprimieren Sie den Quellcode
  • Installieren Sie die folgenden Abhängigkeiten:
    sudo apt-get install zlib1g-dev (wird zum Kompilieren von Python benötigt)
    sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev (wird von Pip benötigt, um SSL-Anfragen zu stellen)
  • Python kompilieren und installieren:
./configure
make
make install
  • Python 3.6 mit Pip sollte installiert sein.
downstream auto-locked support

Hilfreichster Kommentar

Ich habe auch einen ähnlichen Fehler gesehen.

$ sudo python3.6 get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 20061, in <module>
    main()
  File "get-pip.py", line 194, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/__init__.py", line 26, in <module>
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/utils/__init__.py", line 23, in <module>
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/locations.py", line 9, in <module>
ImportError: cannot import name 'sysconfig'

Durch die Installation von python3-distutils konnte dieser Fehler jedoch vermieden werden.
sudo apt-get install python3-distutils

Alle 16 Kommentare

Wenn Sie die Beschreibung meines Problems lesen möchten, werden Sie feststellen, dass ich mir das bereits angesehen habe. Die dort vorgeschlagene Lösung ist mit dieser Version von Ubuntu nicht anwendbar.

Es besteht kein Grund, unhöflich zu sein. Aber für mich ist das Kompilieren von Python auf Ihrem On keine Lösung.

Dieser Importfehler ist die Ursache. Ich versuche es später zu reproduzieren.

@jonbesga Danke für die Problemumgehung, dieses Problem tritt auch mit genau denselben Versionen von Python 3.6 und Ubuntu auf ...

@Tarliton Ich stimme zu, dass das keine Lösung ist. Ich werde es als Workaround umbenennen.

In Bezug auf die Unhöflichkeit, tut mir leid, aber die Aufforderung, das Problem zu sehen, auf das ich bereits in meinem Problem verwiesen habe, bedeutet, dass Sie den Kommentar gepostet haben, ohne mein Problem überhaupt gelesen zu haben.

@jonbesga mein schlechtes, aber ich hätte sagen sollen, dass ich versuchen soll, die Befehle auszuführen, die das andere Problem erwähnt hat.
Wie:

python -c "from distutils import sysconfig"

Ich habe das gerade in einer VM mit Ubuntu 16.04.2 gemacht und kein Problem bekommen. Und Pip installiert.
Ich werde es später mit dem 16.04.4 versuchen.

Das kann ich am 16.04.4 bestätigen,

python3.6 -c "from distutils import sysconfig"

Erzeugt folgenden Fehler:

Traceback (most recent call last):
  File "<string>", line 1, 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 "<string>", line 1, in <module>
ImportError: cannot import name 'sysconfig'

Ich habe versucht, Python 3.6 von ppa:deadsnakes/ppa statt von ppa:jonathonf/python-3.6 zu installieren, und es installiert Pip korrekt. Es sieht so aus, als ob die Version von Jonathonf irgendwie kaputt ist.

Bearbeiten: Ich habe gerade bemerkt, dass einige Kommentare in der Stack Overflow-Antwort dieses Problem mit dem jonathonf-Repository ansprechen

Ich kann bestätigen, dass das Entfernen ppa:jonathonf/python-3.6 und das anschließende Hinzufügen ppa:deadsnakes/ppa und die Neuinstallation python3.6 dieses Problem unter Linux Mint 18.3 behebt.

Informationen zum Entfernen des aktuellen PPA: https://askubuntu.com/a/173209/823909
Neues Python 3.6 PPA hinzufügen: https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get

@tomrunia Ich schlage vor, dass Sie den Link zu https://askubuntu.com/a/310 ändern, da Ihr aktueller Link nicht auf die beste Antwort verweist.

Ich habe auch einen ähnlichen Fehler gesehen.

$ sudo python3.6 get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 20061, in <module>
    main()
  File "get-pip.py", line 194, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/__init__.py", line 26, in <module>
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/utils/__init__.py", line 23, in <module>
  File "/tmp/tmpxvd4x9zn/pip.zip/pip/locations.py", line 9, in <module>
ImportError: cannot import name 'sysconfig'

Durch die Installation von python3-distutils konnte dieser Fehler jedoch vermieden werden.
sudo apt-get install python3-distutils

@wakiyamap Das scheint eine Lösung zu sein, die für # 5356 mit Ubuntu 18.04 LTS funktioniert. In Ubuntu 16.04.4 LTS wurde dieses Paket jedoch umbenannt und löst das Problem nicht.

@jonbesga Ich habe diese Version verwendet.
Ubuntu Xenial (16.04 LTS) (GNU/Linux 4.4.94-mainline-rev1 aarch64 )
ppa:jonathonf/python-3.6

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"

Die CPU ist anders, daher hängt dies möglicherweise nicht mit diesem Fall zusammen.
Verzeihung.

Ich hatte ein ähnliches Problem unter Ubuntu 16.04 (insbesondere "from distutils import dist, sysconfig
ImportError: name 'dist' kann nicht importiert werden") und "sudo apt-get install python3-distutils" hat es gelöst. Danke!

@RandyRomero @wakiyamap Danke, apt install python3-distutils funktioniert auch für mich.

@jonbesga Ich bin am 16.04.4 LTS und es hat funktioniert. BEARBEITEN - Ich verwende Vagrant, habe vor einem Moment "Vagabundenbox-Update" durchgeführt, ich bin auf 20180504)

Im Allgemeinen kein Pip-bezogenes Problem, wenn Sie mich fragen, es hat mehr mit der Ubuntu-Paketierung zu tun

@wakiyamap Danke, deine Lösung apt install python3-distutils hat auch bei mir funktioniert.
Ich habe gerade ein Upgrade auf Python 3.6.5 unter Ubuntu 16.04.4 durchgeführt und Importe für Matplotlib und Aufrufe von pip sind alle mit demselben Fehler fehlgeschlagen.

Dieser Fix muss weit verbreitet werden.

Dieser Thread wurde automatisch gesperrt, da es nach seiner Schließung keine Aktivitäten mehr gegeben hat. Bitte öffnen Sie ein neues Problem für verwandte Fehler.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen