Python error - “ImportError: cannot import name 'dist'”

前端 未结 5 608
遥遥无期
遥遥无期 2021-01-03 20:19

I\'m on Ubuntu 16.04, and I get:

Traceback (most recent call last):
  File \"/home/omermazig/.virtualenvs/fixi/bin/pip\", line 7, in 
    from          


        
相关标签:
5条回答
  • 2021-01-03 20:40

    My case was when I upgraded Ubuntu 18 -> 19. So it reinstalled python and what I needed to do is:

    1. remove old virtual environment

    2. create a new one

    3. install requirements via pip into it

    0 讨论(0)
  • 2021-01-03 20:45

    I ran into this problem after installing Python 3.8 on Ubuntu (I have version 16.04)

    $ lsb_release -d
    Description:     Ubuntu 16.04.6 LTS
    
    1. Reproduce the error

    Just try to import distutils

    $ python3 -c "from distutils import sysconfig"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)
    
    $ sudo apt install python3-distutils          
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package python3-distutils
    

    The package python3-distutils cannot be found

    $ sudo apt install python3-distutils          
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    E: Unable to locate package python3-distutils
    
    1. list available distutils

    What helped was to list all distutil packages using a regexp

    $ apt list *distutils*
    Listing... Done
    python-distutils-extra/xenial,xenial 2.39-1 all
    python-stsci.distutils/xenial,xenial 0.3.7-4 all
    python3-distutils-extra/xenial,xenial 2.39-1 all
    python3-stsci.distutils/xenial,xenial 0.3.7-4 all
    python3.7-distutils/xenial,xenial 3.7.8-1+xenial1 all
    python3.8-distutils/xenial,xenial 3.8.3-1+xenial1 all
    python3.9-distutils/xenial,xenial 3.9.0~b4-1+xenial1 all
    
    1. Install the correct distutils package

    For my Python 3.8 I picked python3.8-distutils and it worked

    $ sudo apt-get install -y python3.8-distutils
    
    0 讨论(0)
  • 2021-01-03 20:49

    Since I run into this issue everytime I update my ubuntu version every six months, then stumble on the exact same SO result, here is my solution.

    If the other solutions listed here don't work (installing python3-distutils), it might be because of different python versions between the system and the virtualenv.

    The easy solution is to destroy your virtualenv, then recreate it from scratch.

    0 讨论(0)
  • 2021-01-03 20:54

    Take a loot at this (similar problem): https://github.com/pypa/pip/issues/5367

    Possible fix:

    • 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)

    • and install:

    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.

    Full credit to jonbesga.

    0 讨论(0)
  • 2021-01-03 21:04

    try it

    sudo apt install python3-distutils
    
    0 讨论(0)
提交回复
热议问题