AssertionError: importlib-metadata .dist-info directory not found

问题描述:由于我的python 程序中导入了click包,但是没有安装该包导致报错如下:

ImportError: No module named click

那么,我们首先想到的就是安装它喽

pip install click

可是用抛出异常了

Collecting click
Collecting importlib-metadata (from click)
Collecting colorama (from click)
  Using cached https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl
Installing collected packages: importlib-metadata, colorama, click
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 335, in run
    prefix=options.prefix_path,
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 837, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1039, in move_wheel_files
    isolated=self.isolated,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 346, in move_wheel_files
    assert info_dir, "%s .dist-info directory not found" % req
AssertionError: importlib-metadata .dist-info directory not found
You are using pip version 8.1.1, however version 21.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

一看这简单,都给出解决方法了,就是干,继续Ctrl+c/v,执行以下命令:

pip install --upgrade pip

又抛出异常了,妈妈咪呀

Collecting pip
  Using cached https://files.pythonhosted.org/packages/00/5f/d6959d6f25f202e3e68e3a53b815af42d770c829c19382d0acbf2c3e2112/pip-21.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-ecEuuQ/pip/setup.py", line 7
        def read(rel_path: str) -> str:
                         ^
    SyntaxError: invalid syntax
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ecEuuQ/pip/
You are using pip version 8.1.1, however version 21.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

这个问题我找了好多教程都是各种方法升级pip的,比如python -m pip install --upgrade pip这种,没啥暖用,,,,

最后,终于找到了一个老哥的帖子,说是这种情况可能是版本升级跨度较大,低级版本无法直接升级到高级版本,,,这好办啊,咋升级跨度别那么大,(我猜可能他怕一下升上去扯着蛋吧。。。。)

咱加个版本号再升级,哎成了

python -m pip install --user --upgrade pip==20.2.4
Collecting pip==20.2.4

  Downloading https://files.pythonhosted.org/packages/cb/28/91f26bd088ce8e22169032100d4260614fc3da435025ff389ef1d396a433/pip-20.2.4-py2.py3-none-any.whl (1.5MB)
    100% |████████████████████████████████| 1.5MB 576kB/s 
Installing collected packages: pip
Successfully installed pip-20.2.4
You are using pip version 20.2.4, however version 21.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
pip install --upgrade pip

结束了,终于好了,我的click这是也安装成功了

pip install click
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: click in ./.local/lib/python2.7/site-packages (0.0.0)
Requirement already satisfied: colorama in ./.local/lib/python2.7/site-packages (from click) (0.4.4)
Collecting importlib-metadata
  Downloading importlib_metadata-2.1.1-py2.py3-none-any.whl (10 kB)
Collecting contextlib2; python_version < "3"
  Downloading contextlib2-0.6.0.post1-py2.py3-none-any.whl (9.8 kB)
Collecting pathlib2; python_version < "3"
  Downloading pathlib2-2.3.6-py2.py3-none-any.whl (17 kB)
Collecting zipp>=0.5
  Downloading zipp-1.2.0-py2.py3-none-any.whl (4.8 kB)
Collecting configparser>=3.5; python_version < "3"
  Downloading configparser-4.0.2-py2.py3-none-any.whl (22 kB)
Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from pathlib2; python_version < "3"->importlib-metadata->click) (1.10.0)
Collecting scandir; python_version < "3.5"
  Downloading scandir-1.10.0.tar.gz (33 kB)
Building wheels for collected packages: scandir
  Building wheel for scandir (setup.py) ... done
  Created wheel for scandir: filename=scandir-1.10.0-cp27-cp27mu-linux_x86_64.whl size=38906 sha256=c12d73e745bdea093b62cc729f689faa2f6c3af3d90fe2289d832ca80f854fde
  Stored in directory: /home/julius/.cache/pip/wheels/58/2c/26/52406f7d1f19bcc47a6fbd1037a5f293492f5cf1d58c539edb
Successfully built scandir
Installing collected packages: contextlib2, scandir, pathlib2, zipp, configparser, importlib-metadata
Successfully installed configparser-4.0.2 contextlib2-0.6.0.post1 importlib-metadata-2.1.1 pathlib2-2.3.6 scandir-1.10.0 zipp-1.2.0

差点忘记附上老哥的文章了

pip2升级报错 ( def read(rel_path: str) ->str: )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

放羊Wa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值