ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source'

徘徊边缘 提交于 2020-02-10 04:26:08

问题


pip3 install is not working and also pip3 is not being able to downgrade to pip19 from pip20.0:

Rayaans-MacBook-Pro:~ rayaangrewal$ pip3 install 
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3", line 10, in <module>
        sys.exit(main())
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
        command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
        module = importlib.import_module(module_path)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
      File "<frozen importlib._bootstrap>", line 983, in _find_and_load
      File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 728, in exec_module
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
        from pip._internal.cli.req_command import RequirementCommand
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
        from pip._internal.operations.prepare import RequirementPreparer
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 16, in <module>
        from pip._internal.distributions import (
      File "/Library/Frameworks/Python.framework/Versions/3.7/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' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/distributions/source/__init__.py)

回答1:


This is a bug in pip 20.0; see https://github.com/pypa/pip/issues/7620

It's fixed in pip 20.0.1. Upgrade to 20.0.1+ or downgrade to 19.3.1. Get get-pip.py and run

python get-pip.py

or

python get-pip.py pip==19.3.1



回答2:


Good answers in @pdh's link to github issues.

When using venv in Python 3.6+ on Ubuntu/LXC with a self-install/self-upgrading pip command during execution, you can use get-pip.py instead:

  1. Activate the virtual environment venv: source bin/activate

  2. Now, instead of the self-updating pip command (which does not work in pip 0.20.0): bin/pip3 install --upgrade pip

  3. You can use:

cd bin
# downloading get-pip.py each time; but you could also remove it from here
# and run this manually only once:
wget https://bootstrap.pypa.io/get-pip.py -O ./get-pip.py
# definitely keep this command:
python3 get-pip.py
cd ..

Result:

Collecting pip
...
Installing collected packages: pip
  Found existing installation: pip 20.0.0
    Uninstalling pip-20.0.0:
      Successfully uninstalled pip-20.0.0
Successfully installed pip-20.0.1

Notes to get-pip.py:

  • It will upgrade all existing pip applications in that /bin folder (e.g. pip, pip3, pip3.6)
  • It will inherently use the arguments install, --upgrade, --force-reinstall
  • It uses the arguments setuptools and wheel by default unless specifically disabled with --no-setuptools or --no-wheel

GET-PIP.PY WARNING

In light of the friendly error message 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., one can instead replace point 3. above with:

bin/python3 -m pip install -U pip [setuptools] [wheel] [--no-cache-dir]


来源:https://stackoverflow.com/questions/59842600/importerror-cannot-import-name-sourcedistribution-from-pip-internal-distrib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!