Python错误 - “ImportError:无法导入名称'dist'”

时间:2021-09-19 18:25:03

I'm on Ubuntu 16.04, and I get:

我在Ubuntu 16.04,我得到:

Traceback (most recent call last):
  File "/home/omermazig/.virtualenvs/fixi/bin/pip", line 7, in <module>
    from pip import main
  File "/home/omermazig/.virtualenvs/fixi/lib/python3.6/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/home/omermazig/.virtualenvs/fixi/lib/python3.6/site-packages/pip/utils/__init__.py", line 23, in <module>
    from pip.locations import (
  File "/home/omermazig/.virtualenvs/fixi/lib/python3.6/site-packages/pip/locations.py", line 9, in <module>
    from distutils import sysconfig
  File "/home/omermazig/.virtualenvs/fixi/lib/python3.6/distutils/__init__.py", line 25, in <module>
    from distutils import dist, sysconfig
ImportError: cannot import name 'dist'

When I run anything with python. This specifically is for trying to run "pip freeze". What to do?

当我用python运行任何东西时。这特别适用于尝试运行“pip freeze”。该怎么办?

2 个解决方案

#1


12  

try it

sudo apt install python3-distutils

#2


0  

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

拿一个战利品(类似的问题):https://github.com/pypa/pip/issues/5367

Possible fix:

  • Download Python source from https://www.python.org/
  • 从https://www.python.org/下载Python源代码

  • Decompress the source code
  • 解压缩源代码

  • Install the following dependencies:

    安装以下依赖项:

    sudo apt-get install zlib1g-dev (needed to compile Python)

    sudo apt-get install zlib1g-dev(需要编译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)

sudo apt-get install libreadline -gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev(Pip需要发出SSL请求)

  • Compile and install Python:
  • 编译并安装Python:

/configure

make

make install

  • Python 3.6 with Pip should be installed.
  • 应该安装带有Pip的Python 3.6。

Full credit to jonbesga.

完全归功于jonbesga。

#1


12  

try it

sudo apt install python3-distutils

#2


0  

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

拿一个战利品(类似的问题):https://github.com/pypa/pip/issues/5367

Possible fix:

  • Download Python source from https://www.python.org/
  • 从https://www.python.org/下载Python源代码

  • Decompress the source code
  • 解压缩源代码

  • Install the following dependencies:

    安装以下依赖项:

    sudo apt-get install zlib1g-dev (needed to compile Python)

    sudo apt-get install zlib1g-dev(需要编译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)

sudo apt-get install libreadline -gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev(Pip需要发出SSL请求)

  • Compile and install Python:
  • 编译并安装Python:

/configure

make

make install

  • Python 3.6 with Pip should be installed.
  • 应该安装带有Pip的Python 3.6。

Full credit to jonbesga.

完全归功于jonbesga。