pip命令不能使用,报错 from pip._internal import cmdoptions ImportError: cannot import name SourceDistribution

转至https://blog.csdn.net/Nemo____/article/details/83886733

pip命令不能使用,报错 from pip._internal import cmdoptions ImportError: cannot import name SourceDistribution

此问题为pip损坏所致
执行pip --version 命令仍然报出此错误

Traceback (most recent call last):
  File "/home/yr/anaconda3/bin/pip", line 8, in <module>
    from pip._internal import main
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 11, in <module>
    from pip._internal.commands import (
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 9, in <module>
    from pip._internal.commands.download import DownloadCommand
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/commands/download.py", line 10, in <module>
    from pip._internal.operations.prepare import RequirementPreparer
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 9, in <module>
    from pip._internal.distributions import (
  File "/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/distributions/__init__.py", line 1, in <module>
    from pip._internal.distributions.source import SourceDistribution
ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source' (/home/yr/anaconda3/lib/python3.7/site-packages/pip/_internal/distributions/source/__init__.py)

解决方法:
参照官网 https://packaging.python.org/tutorials/installing-packages/ 中的一段文字:

If pip isn’t already installed, then first try to bootstrap it from the standard library:

python -m ensurepip --default-pip
If that still doesn’t allow you to run pip:

Securely Download get-pip.py [1]

Run python get-pip.py. [2] This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.

Warning Be cautious if you’re using a Python install that’s managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. You can use python get-pip.py --prefix=/usr/local/ to install in /usr/local which is designed for locally-installed software.

通过如上内容做如下操作:
1、 首先执行命令:   python -m ensurepip --default-pip
2、 下载  get-pip.py 文件  地址为   https://bootstrap.pypa.io/get-pip.py
3、 最后从命令行进入到  get-pip.py  所在的目录,执行命令 :  python get-pip.py  
       注意 此步骤执行的时候可能会报出权限错误, 此时应执行   python get-pip.py  --user

执行 pip --version 查看pip是否安装完成。

亲测,解决了我的问题。

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值